当前位置: 首页>>代码示例>>C#>>正文


C# HttpListener.Start方法代码示例

本文整理汇总了C#中HttpListener.Start方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListener.Start方法的具体用法?C# HttpListener.Start怎么用?C# HttpListener.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpListener的用法示例。


在下文中一共展示了HttpListener.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixtureSetup

 public void FixtureSetup()
 {
     _listener = new HttpListener(_uri.OriginalString);
     _listener.Start();
     _server = new Tracker();
     _server.RegisterListener(_listener);
     _listener.Start();
 }
开发者ID:mrscylla,项目名称:octotorrent,代码行数:8,代码来源:TrackerTests.cs

示例2: StartListener

 static void StartListener()
 {
     listener = new HttpListener();
     listener.Prefixes.Add("http://localhost:57789/");
     listener.Start();
     listener.BeginGetContext(ListenerCallback, listener);
 }
开发者ID:ryanrdl,项目名称:docs.particular.net,代码行数:7,代码来源:Program.cs

示例3: Main

    static void Main()
    {
        Console.Title = "Samples.CustomChecks.3rdPartySystem";
        Console.WriteLine("Press enter key to toggle the server to return a error or success");
        Console.WriteLine("Press any key to exit");

        using (listener = new HttpListener())
        {
            listener.Prefixes.Add("http://localhost:57789/");
            listener.Start();
            listener.BeginGetContext(ListenerCallback, listener);

            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                Console.WriteLine();

                if (key.Key != ConsoleKey.Enter)
                {
                    return;
                }
                listener.Close();
                if (isReturningOk)
                {
                    Console.WriteLine("\r\nCurrently returning success");
                }
                else
                {
                    Console.WriteLine("\r\nCurrently returning error");
                }
                isReturningOk = !isReturningOk;
            }
        }
    }
开发者ID:odelljl,项目名称:docs.particular.net,代码行数:34,代码来源:Program.cs

示例4: Awake

 void Awake()
 {
     listener = new HttpListener();
     listener.Prefixes.Add("http://*:7663/");
     listener.Start();
     listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
 }
开发者ID:rcahoon,项目名称:AerialAssistSim,代码行数:7,代码来源:Vision.cs

示例5: Listener

	public Listener ()
	{
		EndPoints = new List<IPEndPoint> ();

		listener = new HttpListener ();
		listener.Prefixes.Add (KeepAliveTest.URL);
		listener.Start ();
		listener.BeginGetContext (Handle, null);
	}
开发者ID:mono,项目名称:gert,代码行数:9,代码来源:test.cs

示例6: CreateListener

        public HttpListener CreateListener(List<string> addresses)
        {
            var listener = new HttpListener();

            addresses.ForEach(a => listener.Prefixes.Add(a));

            listener.Start();

            return listener;
        }
开发者ID:ihenehan,项目名称:Behavior,代码行数:10,代码来源:Server.cs

示例7: NetEventHandler

        public NetEventHandler()
        {
            BaseUrl = Net.GetUrl(Net.GetIp(IPType.All), Net.FindPort(), "").ToString();
            ServicePointManager.DefaultConnectionLimit = 100;
            _httpListener = new HttpListener();
            _httpListener.Prefixes.Add(BaseUrl);

            _httpListener.Start();
            ThreadPool.QueueUserWorkItem(Listen);
        }
开发者ID:madebysoren,项目名称:NooSphere,代码行数:10,代码来源:NetEventHandler.cs

示例8: StartListener

	public void StartListener (Object args)
	{
		HttpListener listener = new HttpListener ();
		string prefix = string.Format ("http://*:8880/{0}/", args);
		listener.Prefixes.Add (prefix);
		listener.Start ();

		for (; ; ) {
			HttpListenerContext ctx = listener.GetContext ();
			new Thread (new Worker (ctx).ProcessRequest).Start ();
		}
	}
开发者ID:mono,项目名称:gert,代码行数:12,代码来源:host.cs

示例9: Main

	static void Main ()
	{
		HttpListener listener = new HttpListener ();
		listener.IgnoreWriteExceptions = true;
		listener.Prefixes.Add ("http://*:8081/");
		listener.Start ();
		listener.BeginGetContext (RequestHandler, listener);
		while (true) {
			Thread.Sleep (250);
			if (File.Exists ("stop-server.tmp"))
				break;
		}
		listener.Close ();
		File.Create ("finish-server.tmp").Close ();
	}
开发者ID:mono,项目名称:gert,代码行数:15,代码来源:server.cs

示例10: Listen

	private static void Listen ()
	{
		HttpListener listener = new HttpListener ();
		listener.Prefixes.Add ("http://127.0.0.1:8080/a/");
		listener.Start ();

		HttpListenerResponse response = listener.GetContext().Response;
		response.ContentType = "text/xml";

		byte [] buffer = Encoding.UTF8.GetBytes ("<ok/>");
		response.ContentLength64 = buffer.Length;
		Stream output = response.OutputStream;
		output.Write (buffer, 0, buffer.Length);
		output.Close ();
		listener.Stop ();
	}
开发者ID:mono,项目名称:gert,代码行数:16,代码来源:test.cs

示例11: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Started");
            HttpListener listener = new HttpListener();

            listener.Prefixes.Add("http://localhost:8888/decorator/");

            listener.Start();

            while (true)
            {
                HttpListenerContext ctx = listener.GetContext();
                Console.WriteLine("connected");
                ProcessRequest(ctx);
            }
        }
开发者ID:Lydiasaurus,项目名称:Personal,代码行数:16,代码来源:Program.cs

示例12: Main

	static int Main ()
	{
		HttpListener listener = new HttpListener ();
		listener.Prefixes.Add ("http://" + IPAddress.Loopback.ToString () + ":8001/");

		listener.Start ();
		IAsyncResult result = listener.BeginGetContext (new AsyncCallback (ListenerCallback), listener);

		HttpWebRequest request = (HttpWebRequest) WebRequest.Create ("http://" + IPAddress.Loopback.ToString () + ":8001/?a=1&b=2");
		request.Accept = "image/png,text/html";
		request.Method = "GET";
		HttpWebResponse response = (HttpWebResponse) request.GetResponse ();
		response.Close ();
		result.AsyncWaitHandle.WaitOne ();

		return exitCode;
	}
开发者ID:mono,项目名称:gert,代码行数:17,代码来源:test.cs

示例13: Main

    static void Main(string[] args)
    {
        var port   = "1982";
        var root   = ".";
        var prefix = String.Format("http://*:{0}/", port);

        Log("listening {0}", prefix);

        var listener = new HttpListener();
        listener.Prefixes.Add(prefix);
        listener.Start();

        while (true) {
          var context  = listener.GetContext();
          var request  = context.Request;
          var response = context.Response;

          Log("{0} {1}", request.HttpMethod, request.RawUrl);

          if (request.RawUrl == "/api") {
        ApiResponse(response, request);
          }
          else {
        var path = root + request.RawUrl;

        try {
          var content = File.ReadAllBytes(path);
          response.ContentType = "text/plain";
          response.AppendHeader("Content-Length", content.Length.ToString());
          response.OutputStream.Write(content, 0, content.Length);
        }
        catch (FileNotFoundException e) {
          ErrorResponse(response, 404, e);
        }
        catch (UnauthorizedAccessException e) {
          ErrorResponse(response, 403, e);
        }
        catch (Exception e) {
          ErrorResponse(response, 500, e);
        }
          }
          Log("  -> {0}", response.StatusCode);
          response.Close();
        }
    }
开发者ID:gfx,项目名称:mono-simple-httpd,代码行数:45,代码来源:SimpleHttpd.cs

示例14: run_server

	static void run_server ()
	{
		HttpListener listener = new HttpListener ();
		listener.Prefixes.Add (url);
		listener.Start ();

		while (server_count < count) {
			HttpListenerContext context = listener.GetContext ();
			HttpListenerResponse response = context.Response;
			string responseString = "my data";
			byte [] buffer = Encoding.UTF8.GetBytes (responseString);
			response.ContentLength64 = buffer.Length;
			Stream output = response.OutputStream;
			output.Write (buffer, 0, buffer.Length);
			output.Close ();
			server_count++;
		}
	}
开发者ID:mono,项目名称:gert,代码行数:18,代码来源:test1.cs

示例15: Start

    public void Start(int port)
    {
        if (listener != null && listener.IsListening)
        {
            return;
        }

        System.Diagnostics.Process process = new System.Diagnostics.Process();
        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        startInfo.FileName = "cmd.exe";
        startInfo.Arguments = "netsh http add urlacl url=http://+:" + port.ToString() + "/ user=" + Environment.UserDomainName + "\\" + Environment.UserName;
        process.StartInfo = startInfo;
        process.Start();

        listener = new HttpListener();
        //listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;

        try
        {
            //listener.Prefixes.Add("http://localhost:" + port.ToString() + "/");
            listener.Prefixes.Add("http://*:" + port.ToString() + "/");
            //listener.Prefixes.Add("http://ip:2006/test/");
            //hl.Prefixes.Add("http://*:7867/test/");

            listener.Start();
            //Console.ReadKey();

        }
        catch (Exception e)
        {
            //Console.WriteLine("Error!!!!!!!!!!!!!!");
            Console.ReadKey();
            throw e;
        }

        //Console.WriteLine("Started!!!!!!!!!!!!!!!!");
        //Console.ReadKey();

        running = true;

        Thread thread = new Thread(new ThreadStart(listen));
        thread.Start();
    }
开发者ID:jcamelina,项目名称:oneapi-dot-net,代码行数:44,代码来源:Copy+of+PushServerSimulator.cs


注:本文中的HttpListener.Start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。