Пример #1
0
 private bool startServer()
 {
     initConf();
     try
     {
         listenThread = new Thread(Server);
         listenThread.Start();
         OnlineConnectTimer.Interval = timeOut;
         OnlineConnectTimer.Start();
         return(true);
         //textBox1.Invoke(cbSetTextBox, "监听程序启动成功,端口:" + hostPort);
     }
     catch (Exception ex)
     {
         //textBox1.Invoke(cbSetTextBox, "监听启动异常:" + ex.Message);
         writeLog("监听启动异常:" + ex.Message);
         return(false);
     }
 }
Пример #2
0
 private bool stopServer()
 {
     try
     {
         OnlineConnectTimer.Stop();
         listenEnable = false;
         listener.Stop();
         listenThread.Abort();
         listenThread = null;
         //if (netStream != null)
         //    netStream.Dispose();
         //if (client != null)
         //    client.Close();
         //textBox1.Invoke(cbSetTextBox, "服务端程序已关闭...");
         writeLog("服务端监听已关闭...");
         return(true);
     }
     catch (Exception ex)
     {
         //textBox1.Invoke(cbSetTextBox, "服务端关闭出现异常!!!");
         writeLog("服务端关闭出现异常!!!");
         return(false);
     }
 }