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


C# HttpListener.BeginGetContext方法代码示例

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


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

示例1: 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

示例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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: RemotingHttpListener

		public RemotingHttpListener (IPAddress addr, int port, HttpServerTransportSink sink)
		{
			this.sink = sink;
			bool find_port = false;
			if (port == 0)
				find_port = true;

			string address = null;
			if (addr == IPAddress.Any)
				address = "*";
#if NET_2_0
			else if (addr == IPAddress.IPv6Any)
				address = "*";
#endif
			else
				address = addr.ToString ();

			listener = new HttpListener ();
			while (true) {
				Random rnd = null;
				if (find_port) {
					if (rnd == null)
						rnd = new Random ();
					port = rnd.Next (1025, 65000);
				}
				try {
					listener.Prefixes.Add (String.Format ("http://{0}:{1}/", address, port));
					listener.Start ();
					local_port = port;
					break;
				} catch (Exception e) {
					if (!find_port)
						throw;
					listener.Prefixes.Clear ();
					// Port already in use
				}
			}
			listener.BeginGetContext (new AsyncCallback (OnGetContext), null);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:39,代码来源:RemotingHttpListener.cs

示例8: Main

        static void Main(string[] args)
        {
            db = new SQLiteConnection(ServerSettings.Default.ConnectionString);
            db.Open();

            CreateTables();

            bool running = true;
            Console.CancelKeyPress += (s, e) =>
            {
                running = false;
                e.Cancel = true;
            };

            Console.WriteLine("Press Ctrl+C to quit.");

            using (var http = new HttpListener())
            {
                http.Prefixes.Add(ServerSettings.Default.Prefix);
                http.Start();

                while (running)
                {
                    HttpListenerContext context = null;
                    try
                    {
                        var result = http.BeginGetContext(null, null);
                        while (!result.IsCompleted)
                        {
                            if (running == false)
                                goto quit;
                            Thread.Sleep(0);
                        }
                        context = http.EndGetContext(result);
                        switch (context.Request.HttpMethod)
                        {
                            case "POST":
                                DispatchPost(context);
                                break;
                            default:
                                DispatchGet(context);
                                break;
                        }

                    }
                    catch (Exception ex)
                    {
                        using (var sw = new StreamWriter(context.Response.OutputStream, Encoding.UTF8))
                        {
                            sw.Write(ex.ToString());
                        }
                        context.Response.StatusCode = 500;
                    }
                    finally
                    {
                        if (context != null)
                            context.Response.Close();
                    }
                }
            quit:
                db.Close();
            }
        }
开发者ID:MasterQ32,项目名称:Microblog,代码行数:63,代码来源:Program.cs

示例9: Start

    // Use this for initialization
    void Start()
    {
        _listener = new HttpListener();
        _listener.Prefixes.Add ("http://127.0.0.1:8080/");

        _listener.Start();

        _listener.BeginGetContext(new AsyncCallback(ListenerCallback),_listener);
    }
开发者ID:rxra,项目名称:UnityHTTPListener,代码行数:10,代码来源:HTTPServer.cs

示例10: Main

        static void Main(string[] args)
        {
            uriBaseAddress = args[0];
            if (!uriBaseAddress.EndsWith("/"))
                uriBaseAddress += "/";

            useV2Host = false;
            if (args.Length > 1)
                useV2Host = bool.Parse(args[1]);

            string waitHandleName = null;
            if (args.Length > 2)
                waitHandleName = args[2];

            serviceType = Assembly.GetExecutingAssembly()
                .GetTypes()
                .Single(t => !t.IsAbstract 
                    && typeof(Microsoft.OData.Service.IRequestHandler).IsAssignableFrom(t));

            HttpListener listener = new HttpListener();
            try
            {
                listener.Prefixes.Add(uriBaseAddress);
                listener.Start();
                listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred:");
                Console.WriteLine(e.ToString());
                listener.Abort();
                Console.ReadLine();
            }

            // both of the following cases will block, so there is no need for a loop
            if (waitHandleName == "Debug" || string.IsNullOrEmpty(waitHandleName))
            {
                Console.WriteLine("Running in Debug mode, please press any key to exit");
                // blocks until key pressed
                Console.Read();
            }
            else
            {
                // if the wait handle name was specified on the command line, then the test infrastructure
                // must have created one for us to wait on
                // we do this instead of blocking on the command line because it has proven to be more robust
                // and much easier to shut down the service when disposing the workspace
                EventWaitHandle waitHandle = EventWaitHandle.OpenExisting(waitHandleName);

                // blocks until the wait handle is triggered by the test infrastructure
                waitHandle.WaitOne();
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:53,代码来源:IDataServiceHostRunner.cs


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