private void ConsoleListenerThread() { try { CSL = new TcpListener(new System.Net.IPEndPoint(0, consolePort)); CSL.Start(); while (true) { CWC = new TCP.WorkerClient(CSL.AcceptTcpClient()); CWC.InitOps(); CWC.Disconnected += CWCDisconnected; CWC.MessageArrived += CWCMessageArrived; Logger.MajorInfo("Console client from " + CWC.ClientIP() + " is connected"); consoleCurCons = 1; while (consoleCurCons == 1) { System.Threading.Thread.Sleep(50); } } } catch (Exception ex) { Logger.MajorInfo("Exception on console listening thread (" + ex.Message + ")"); if (CSL != null) { CSL.Stop(); CSL = null; } } }
private void ListenerThread() { WC = null; try { SL = new TcpListener(new System.Net.IPEndPoint(0, port)); SL.Start(); while (true) { TCP.WorkerClient wClient = new TCP.WorkerClient(SL.AcceptTcpClient()); wClient.InitOps(); wClient.Disconnected += WCDisconnected; wClient.MessageArrived += WCMessageArrived; Logger.MajorInfo("Client from " + wClient.ClientIP() + " is connected"); curCons += 1; bool slotedIt = false; for (int i = 0; i < WC.GetUpperBound(0); i++) { if ((WC[i] == null) || (WC[i].IsConnected == false)) { WC[i] = wClient; slotedIt = true; } } if (slotedIt == false) { Array.Resize(ref WC, WC.GetUpperBound(0)); WC[WC.GetUpperBound(0) - 1] = wClient; } while (curCons >= maxCons) { Thread.Sleep(50); } } } catch (Exception ex) { Logger.MajorInfo("Exception on listening thread (" + ex.Message + ")"); if (SL != null) { SL.Stop(); SL = null; } } }