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


C# HttpListener类代码示例

本文整理汇总了C#中HttpListener的典型用法代码示例。如果您正苦于以下问题:C# HttpListener类的具体用法?C# HttpListener怎么用?C# HttpListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: AddPrefix

 public static void AddPrefix(string uriPrefix, HttpListener httpListener)
 {
     lock (((ICollection) _ipToEndpoints).SyncRoot)
     {
         addPrefix (uriPrefix, httpListener);
     }
 }
开发者ID:richardfeng,项目名称:UnitySocketIO-WebSocketSharp,代码行数:7,代码来源:EndPointManager.cs

示例2: AddPrefix

 public static void AddPrefix(string prefix, HttpListener listener)
 {
     lock (_ipToEndpoints)
     {
         AddPrefixInternal(prefix, listener);
     }
 }
开发者ID:unosquare,项目名称:embedio,代码行数:7,代码来源:EndPointManager.cs

示例3: getEndPointListener

    private static EndPointListener getEndPointListener (
      IPAddress address, int port, HttpListener httpListener, bool secure)
    {
      Dictionary<int, EndPointListener> endpoints = null;
      if (_ipToEndpoints.ContainsKey (address)) {
        endpoints = _ipToEndpoints [address];
      }
      else {
        endpoints = new Dictionary<int, EndPointListener> ();
        _ipToEndpoints [address] = endpoints;
      }

      EndPointListener epListener = null;
      if (endpoints.ContainsKey (port)) {
        epListener = endpoints [port];
      }
      else {
        epListener = new EndPointListener (
          address,
          port,
          secure,
          httpListener.CertificateFolderPath,
          httpListener.DefaultCertificate);

        endpoints [port] = epListener;
      }

      return epListener;
    }
开发者ID:JChan106,项目名称:HACKPOLY16,代码行数:29,代码来源:EndPointManager.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: 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

示例6: ListenThread

    private void ListenThread()
    {
        try
        {
            listener = new HttpListener();

            foreach (string prefix in prefixes)
            {
                listener.Prefixes.Add(prefix);
            }

            listener.Start();

            while (true)
            {
                HttpListenerContext context = listener.GetContext();

                Debug.LogFormat("Recieved request from {0}.", context.Request.RemoteEndPoint.ToString());

                context.Response.StatusCode = 200;

                lock (waitingContexts)
                {
                    waitingContexts.AddLast(context);
                }
            }
        }
        catch(Exception e)
        {
            Debug.LogErrorFormat("Web server error at {0}.", e.Source);
            Debug.LogError(e.Message, this);
        }
    }
开发者ID:bonbombs,项目名称:CrimeTimeUNET,代码行数:33,代码来源:WebServer.cs

示例7: EndPointListener

        private ArrayList _unhandled; // List<ListenerPrefix> unhandled; host = '*'

        #endregion Fields

        #region Constructors

        public EndPointListener(HttpListener listener, IPAddress addr, int port, bool secure)
        {
            Listener = listener;

            if (secure)
            {
            #if SSL
                this.secure = secure;
                cert = listener.LoadCertificateAndKey (addr, port);
            #else
                throw new Exception("SSL is not supported");
            #endif
            }

            _endpoint = new IPEndPoint(addr, port);
            _sock = new Socket(addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _sock.Bind(_endpoint);
            _sock.Listen(500);
            var args = new SocketAsyncEventArgs {UserToken = this};
            args.Completed += OnAccept;
            Socket dummy = null;
            Accept(_sock, args, ref dummy);
            _prefixes = new Hashtable();
            _unregistered = new Dictionary<HttpConnection, HttpConnection>();
        }
开发者ID:unosquare,项目名称:embedio,代码行数:31,代码来源:EndPointListener.cs

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

示例9: AddPrefix

 public static void AddPrefix(ILogger logger, string prefix, HttpListener listener)
 {
     lock (ip_to_endpoints)
     {
         AddPrefixInternal(logger, prefix, listener);
     }
 }
开发者ID:softworkz,项目名称:SocketHttpListener,代码行数:7,代码来源:EndPointManager.cs

示例10: AddListener

        public static void AddListener(HttpListener listener)
        {
            ArrayList added = new ArrayList();

            try
            {
                lock (ip_to_endpoints)
                {
                    foreach (string prefix in listener.Prefixes)
                    {
                        AddPrefixInternal(prefix, listener);

                        added.Add(prefix);
                    }
                }
            }
            catch
            {
                foreach (string prefix in added)
                {
                    RemovePrefix(prefix, listener);
                }

                throw;
            }
        }
开发者ID:jamesaxl,项目名称:reactor,代码行数:26,代码来源:EndPointManager.cs

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

示例12: Server

        public Server()
        {
            this.httpListener = new HttpListener();

            this.httpListener.Prefixes.Add("http://localhost:8080/");
            this.httpListener.Prefixes.Add("http://127.0.0.1:8080/");
            this.httpListener.Prefixes.Add("http://test.localhost:8080/");
        }
开发者ID:MathieuMorrissette,项目名称:Simple-HTTP-Server,代码行数:8,代码来源:Server.cs

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

示例14: Configure

  public void Configure(string[] prefixes, string vdir, string pdir)
  {
    _virtualDir = vdir;
    _physicalDir = pdir;
    _listener = new HttpListener();

    foreach (string prefix in prefixes)
      _listener.Prefixes.Add(prefix);
  }
开发者ID:wbrussell,项目名称:xmlrpcnet,代码行数:9,代码来源:HttpListenerWrapper.cs

示例15: WebAppServer

 /// <summary>
 /// Create an instance of <see cref="WebAppServer"/>.
 /// </summary>
 /// <param name="urlReservation">
 /// The URL reservation to listen on. This string is similar to a URL, but the
 /// hostname may be a strong wildcard ('+') or a weak wildcard ('*'). E.g. "http://+:8080/".
 /// </param>
 public WebAppServer(string urlReservation)
 {
     _urlRegex = new Regex("^" + urlReservation.Replace("*", ".*?").Replace("+", ".*?"), RegexOptions.IgnoreCase);
     _listener = new HttpListener();
     _listener.Prefixes.Add(urlReservation);
     _disconnectHandler = new DisconnectHandler(_listener);
     var uri = new Uri(urlReservation.Replace("*", "localhost").Replace("+", "localhost"));
     _webAppConfiguration = new WebAppConfiguration(uri);
     StaticFiles = new StaticFileSpecCollection();
 }
开发者ID:jkells,项目名称:WebAppHost,代码行数:17,代码来源:WebAppServer.cs


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