示例#1
0
 protected override void OnClosed(EventArgs e)
 {
     timer.Stop();
     timer.Dispose();
     if (WebSocketService != null)
     {
         WebSocketService.Dispose();
         WebSocketService = null;
     }
     base.OnClosed(e);
 }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            string ip          = textBox_Ip.Text;
            string port        = textBox_Port.Text;
            string subProtocol = textBox_SubProtocol.Text;

            errorProvider1.Clear();

            if (string.IsNullOrEmpty(ip))
            {
                errorProvider1.SetError(textBox_Ip, "请输入服务监控的IP");
                button1.Enabled = true;
                return;
            }
            if (string.IsNullOrEmpty(port))
            {
                errorProvider1.SetError(textBox_Port, "请输入服务监控的端口");
                button1.Enabled = true;
                return;
            }


            if (!serverIsStart)
            {
                WebSocketService = new WebSocketService(ip, int.Parse(port), subProtocol);
                WebSocketService.OnAddWebSocket               += WebSocketService_OnAddWebSocket;
                WebSocketService.OnAuthentication             += WebSocketService_OnAuthentication;
                WebSocketService.OnReceiveMessage             += WebSocketService_OnReceiveMessage;
                WebSocketService.OnRemoveWebSocket            += WebSocketService_OnRemoveWebSocket;
                WebSocketService.OnWebSocketServiceBeginStart += WebSocketService_OnWebSocketServiceBeginStart;
                WebSocketService.OnWebSocketServiceClose      += WebSocketService_OnWebSocketServiceClose;
                WebSocketService.OnWebSocketServiceStart      += WebSocketService_OnWebSocketServiceStart;
                WebSocketService.OnWebSocketServiceStop       += WebSocketService_OnWebSocketServiceStop;
                WebSocketService.Start();
            }
            else
            {
                WebSocketService.Dispose();
                WebSocketService = null;
            }

            serverIsStart = !serverIsStart;
            setButton1Text();
            button1.Enabled = true;
        }
示例#3
0
 private void WebSocketService_OnWebSocketServiceBeginStart(WebSocketService service, System.Net.HttpListener httpListener)
 {
     Console.WriteLine("服务准备开启");
 }
示例#4
0
 private void WebSocketService_OnWebSocketServiceStop(WebSocketService service, System.Net.HttpListener httpListener)
 {
     Console.WriteLine("服务停止");
 }