コード例 #1
0
ファイル: ChatService.cs プロジェクト: windygu/back-end-study
 /// <summary>
 /// 服务开启前触发
 /// </summary>
 /// <param name="service"></param>
 /// <param name="httpListener"></param>
 private void ChatService_OnWebSocketServiceBeginStart(WebSocketService.Core.WebSocketService service, System.Net.HttpListener httpListener)
 {
     if (CreateRepositoryFunc == null)
     {
         httpListener.Close();
         throw new Exception("未设置资创建源库方法!");
     }
     using (var repository = CreateRepositoryFunc())
     {
         Users = repository.GetUsers().ToList();
     }
 }
コード例 #2
0
        private bool TryConnectLocalIP()
        {
            using (var listener = new System.Net.HttpListener())
            {
                listener.Prefixes.Add(ExternalUrl);
                try
                {
                    listener.Start();
                }
                catch (System.Net.HttpListenerException)
                {
                    return(false);
                }
                listener.Close();
            }

            return(true);
        }
コード例 #3
0
        private bool TryConnectLocalIP()
        {
            using (var listener = new System.Net.HttpListener())
            {
                listener.Prefixes.Add(ExternalUrl);
                try
                {
                    listener.Start();
                }
                catch (System.Net.HttpListenerException e)
                {
                    e.ToString();
                    //System.Console.WriteLine(e);
                    return(false);
                }
                listener.Close();
            }

            return(true);
        }
コード例 #4
0
        private async void Listen()
        {
            this.WriteLogMethodName();
            while (true)
            {
                var context = await HttpListener.GetContextAsync();

                Console.WriteLine("Client connected");
                //Console.WriteLine(context.Request.AcceptTypes.ToString());

                WriteLog("Client Connected");
                WriteLog("Request Url: {0}", context.Request.Url);
                WriteLog("Request Url Absolute Path: {0}", context.Request.Url.AbsolutePath);
                WriteLog("Request Url Path and Query: {0}", context.Request.Url.PathAndQuery);
                WriteLog("Request UserAgent: {0}", context.Request.UserAgent);
                WriteLog("Request UserHostAddress: {0}", context.Request.UserHostAddress);
                WriteLog("Request UserHostName: {0}", context.Request.UserHostName);
                WriteLog("Request UserLanguages: {0}", context.Request.UserLanguages == null ? "" : string.Join(",", context.Request.UserLanguages));
                ProcessRequest(context);
            }

            HttpListener.Close();
        }
コード例 #5
0
        private bool TryConnectLocalIP()
        {
            using (var listener = new System.Net.HttpListener())
            {
                listener.Prefixes.Add(ExternalUrl);
                try
                {
                    listener.Start();
                }
                catch(System.Net.HttpListenerException e)
                {
                    e.ToString();
                    //System.Console.WriteLine(e);
                    return false;
                }
                listener.Close();
            }

            return true;
        }
コード例 #6
0
 public void Stop()
 {
     _listener.Close();
 }
コード例 #7
0
 public void Dispose()
 {
     _listener.Stop();
     _listener.Close();
     _handlers.Clear();
 }