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


C# HttpListener.BeginGetContext方法代码示例

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


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

示例1: Start

        public void Start(string bindUrl)
        {
            Ensure.NotNull(bindUrl, nameof(bindUrl));

            _httpListener = new HttpListener { IgnoreWriteExceptions = false };
            _httpListener.Prefixes.Add(bindUrl);
            _httpListener.Start();


            AsyncCallback acceptConnection = null;
            acceptConnection = state =>
            {
                try
                {
                    HttpListenerContext clientContext = _httpListener.EndGetContext(state);
                    Log.Info($"New Ecr connection from: {clientContext.Request.RemoteEndPoint}");

                    ProcessAsync(clientContext);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
                finally
                {
                    _httpListener.BeginGetContext(acceptConnection, null);
                }
            };

            _httpListener.BeginGetContext(acceptConnection, null);

            RegisterActions();
        }
开发者ID:alaidas,项目名称:PlugNPay,代码行数:33,代码来源:PosHub.cs

示例2: Start

 public void Start()
 {
     httpListener = new HttpListener();
     httpListener.Prefixes.Add("http://localhost:" + this.ListenPort + "/");
     httpListener.Start();
     httpListener.BeginGetContext(this.OnNewRequest, null);
 }
开发者ID:semirs,项目名称:CellAO,代码行数:7,代码来源:MicroHttpServer.cs

示例3: Sewers

        public Sewers()
        {
            _listener = new HttpListener();
            string prefix = "http://*:81/";
            _listener.Prefixes.Add(prefix);
            _messages = new Demonic("127.0.0.1");
            _messages.setName("Black Temple");
            _messages.setPort(11201);
            _messages.addMethod("RESPONSE");
            _messages.setCallback(onMessageRecieved);
            _messages.init();

            try
            {
                _listener.Start();
                while (true)
                {
                    System.Console.WriteLine("Listening");
                    IAsyncResult result = _listener.BeginGetContext(new AsyncCallback(ListenerCallback), _listener);
                    result.AsyncWaitHandle.WaitOne();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }
开发者ID:pldcanfly,项目名称:demonhunter,代码行数:28,代码来源:Sewers.cs

示例4: ListenTo

        /// <summary>
        /// Starts the Authorisation listener to listen to the specified port.
        /// </summary>
        /// <param name="port"></param>
        public void ListenTo(int port)
        {
            if (!HttpListener.IsSupported)
            {
                Debug.Write("AuthListener unsupported: Windows XP SP2 or Server 2003 is required");
                throw new NotSupportedException("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
            }

            try
            {
                this._server = new HttpListener();

                var prefix = String.Format("http://localhost:{0}/", port);
                this._server.Prefixes.Add(prefix);
                Debug.WriteLine("Prefix " + prefix + " added.");

                // Start listening for client requests.
                this._server.Start();
                Debug.WriteLine("Waiting for a connection... ");

                // Start waiting for a request
                _server.BeginGetContext(new AsyncCallback(ListenerCallback), _server);
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
                this.Stop();
            }
        }
开发者ID:JonCubed,项目名称:SWCombine-SDK-CSharp,代码行数:33,代码来源:AuthListener.cs

示例5: Start

		public void Start()
		{
			listener = new HttpListener();
			string virtualDirectory = Configuration.VirtualDirectory;
			if (virtualDirectory.EndsWith("/") == false)
				virtualDirectory = virtualDirectory + "/";
			listener.Prefixes.Add("http://+:" + Configuration.Port + virtualDirectory);
			switch (Configuration.AnonymousUserAccessMode)
			{
				case AnonymousUserAccessMode.None:
					listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;
					break;
                case AnonymousUserAccessMode.All:
			        break;
				case AnonymousUserAccessMode.Get:
					listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication |
						AuthenticationSchemes.Anonymous;
			        listener.AuthenticationSchemeSelectorDelegate = request =>
			        {
                        return request.HttpMethod == "GET" || request.HttpMethod == "HEAD" ? 
                            AuthenticationSchemes.Anonymous : 
                            AuthenticationSchemes.IntegratedWindowsAuthentication;
			        };
					break;
                default:
			        throw new ArgumentException("Cannot understand access mode: " + Configuration.AnonymousUserAccessMode   );
			}

			listener.Start();
			listener.BeginGetContext(GetContext, null);
		}
开发者ID:nathanpalmer,项目名称:ravendb,代码行数:31,代码来源:HttpServer.cs

示例6: Main

        private static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net_server.config"));

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.Name = "Entry";

            Database = new Database();
            GameData = new XmlData();

            InstanceId = Guid.NewGuid().ToString();
            Console.CancelKeyPress += (sender, e) => e.Cancel = true;

            if (RunPreCheck(port))
            {
                listener = new HttpListener();
                listener.Prefixes.Add($"http://*:{port}/");
                listener.Start();
                listener.BeginGetContext(ListenerCallback, null);
                Logger.Info($"Listening at port {port}...");
            }
            else
                Logger.Error($"Port {port} is occupied");

            while (Console.ReadKey(true).Key != ConsoleKey.Escape) ;

            Logger.Info("Terminating...");
            while (currentRequests.Count > 0) ;
            listener?.Stop();
        }
开发者ID:BlackRayquaza,项目名称:PhoenixRealms,代码行数:30,代码来源:Program.cs

示例7: HttpServer

 public HttpServer()
 {
     this.listener = new HttpListener();
     listener.Prefixes.Add(URL + "/");
     listener.Start();
     listener.BeginGetContext(new AsyncCallback(ListenerCallback), null);
 }
开发者ID:zensend,项目名称:zensend_csharp_api,代码行数:7,代码来源:HttpServer.cs

示例8: ServerModel

 public ServerModel()
 {
     mListener = new HttpListener();
     mListener.Prefixes.Add( "http://*:8181/" );
     mListener.Start();
     mListener.BeginGetContext( new AsyncCallback( ListenerCallback ), mListener );
 }
开发者ID:RedRecondite,项目名称:TicTacToe,代码行数:7,代码来源:ServerModel.cs

示例9: Setup

        public void Setup()
        {
            requestedUrl.Clear();
            partialData = false;
            int i;
            for (i = 0; i < 1000; i++)
            {
                try
                {
                    listener = new HttpListener();
                    listener.Prefixes.Add(string.Format(listenerURL, i));
                    listener.Start();
                    break;
                }
                catch
                {

                }
            }
            listener.BeginGetContext(GotContext, null);
            rig = TestRig.CreateMultiFile();
            connection = new HttpConnection(new Uri(string.Format(listenerURL, i)));
            connection.Manager = rig.Manager;

            id = new PeerId(new Peer("this is my id", connection.Uri), rig.Manager);
            id.Connection = connection;
            id.IsChoking = false;
            id.AmInterested = true;
            id.BitField.SetAll(true);
            id.MaxPendingRequests = numberOfPieces;
            
            requests = rig.Manager.PieceManager.Picker.PickPiece(id, new List<PeerId>(), numberOfPieces);
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:33,代码来源:TestWebSeed.cs

示例10: HttpServer

        public HttpServer(string baseDirectory)
        {
            this.baseDirectory = baseDirectory;
            var rnd = new Random();

            for (int i = 0; i < 100; i++)
            {
                int port = rnd.Next(49152, 65536);

                try
                {
                    listener = new HttpListener();
                    listener.Prefixes.Add("http://localhost:" + port + "/");
                    listener.Start();

                    this.port = port;
                    listener.BeginGetContext(ListenerCallback, null);
                    return;
                }
                catch (Exception x)
                {
                    listener.Close();
                    Debug.WriteLine("HttpListener.Start:\n" + x);
                }
            }

            throw new ApplicationException("Failed to start HttpListener");
        }
开发者ID:jschell,项目名称:JabbR.Eto,代码行数:28,代码来源:HttpServer.cs

示例11: AsyncHttpServer

 public AsyncHttpServer()
 {
     _listener = new HttpListener();
     _listener.Prefixes.Add("http://+:80/");
     _listener.Start();
     _listener.BeginGetContext(GetContext, null);
 }
开发者ID:lefoulkrod,项目名称:async-net,代码行数:7,代码来源:AsyncHttpServer.cs

示例12: DetergentHttpListener

        public DetergentHttpListener(
            string uriPrefix,
            string applicationPath,
            IDetergentHttpHandler detergentHttpHandler)
        {
            if (uriPrefix == null)
                throw new ArgumentNullException("uriPrefix");
            if (applicationPath == null)
                throw new ArgumentNullException("applicationPath");
            if (detergentHttpHandler == null) throw new ArgumentNullException("detergentHttpHandler");

            this.uriPrefix = uriPrefix;
            this.applicationPath = applicationPath;
            this.detergentHttpHandler = detergentHttpHandler;
            httpListener = new HttpListener();

            applicationRootUrl = new Uri(new Uri(uriPrefix), applicationPath).ToString();
            if (false == applicationRootUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase))
                applicationRootUrl = applicationRootUrl + '/';

            httpListener.Prefixes.Add(applicationRootUrl);

            DumpDiagnostics();

            httpListener.Start();
            IAsyncResult result = httpListener.BeginGetContext(WebRequestCallback, httpListener);
        }
开发者ID:Ryks,项目名称:detergent,代码行数:27,代码来源:DetergentHttpListener.cs

示例13: Main

		static HttpListener listener; // http server providing clipboard history selection

		public static void Main (string[] args)
		{
			// make UI methods for clipboard access available
			Application.Init ();

			// setup http interface
			listener = new HttpListener();
			listener.Prefixes.Add("http://*:5544/");
			listener.Start();
			listener.BeginGetContext(ProcessRequest, null);

			// initialize access to clipboard
			clippy = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", false));

			// schedule polling of clipboard content
			timer = new System.Timers.Timer(300);
			timer.Elapsed += new System.Timers.ElapsedEventHandler(ReadClipboardUI);
			timer.Start();

			// just to prevent termination of the app
			Application.Run();

			// shutdown http interface
			listener.Stop();
		}
开发者ID:eugenkrizo,项目名称:tablet-clipboard,代码行数:27,代码来源:Main.cs

示例14: Run

        protected void Run()
        {
            _listener = new HttpListener();
            _listener.Prefixes.Add(Host);
            _listener.Start();

            _listener.BeginGetContext(GetContext, null);
        }
开发者ID:Mitch528,项目名称:TrueCraftPushRestart,代码行数:8,代码来源:GitHubHookListener.cs

示例15: Start

 /// <summary>
 /// 启动监听
 /// </summary>
 public static void Start(int port)
 {
     listener = new HttpListener();
     listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
     listener.Prefixes.Add(string.Format("http://*:{0}/", port));
     listener.Start();
     listener.BeginGetContext(new System.AsyncCallback(GetContextCallBack), listener);
 }
开发者ID:cnalwaysroad,项目名称:Urge,代码行数:11,代码来源:StateListener.cs


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