/// <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(); } }
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); }
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); }
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(); }
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; }
public void Stop() { _listener.Close(); }
public void Dispose() { _listener.Stop(); _listener.Close(); _handlers.Clear(); }