} // O(1) private void sendMsgToOtherClient(clientObj client) { try { client.sendMsg(Encoding.UTF8.GetBytes("\n\r < " + this.myInput + "\r > ")); } catch { clientsList.Remove(client); return; } } // O(N)
} // O(N) private void whomToSendMsg(clientObj client) { if (client == this) { this.mySocket.Send(Encoding.UTF8.GetBytes("\r > ")); } else { this.sendMsgToOtherClient(client); } } // O(1)
static void Main(string[] args) { Socket server = null; IPAddress addr = IPAddress.Parse("127.0.0.1"); List <clientObj> clientsList = new List <clientObj>(); try { server = new Socket(addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp); server.Bind(new IPEndPoint(addr, 9999)); server.Listen(100); while (true) { clientObj client = new clientObj(server.Accept(), clientsList); clientsList.Add(client); Thread newThread = new Thread(client.startBroadcasting); newThread.Start(); } } catch { Console.WriteLine("Error acurred server can't run or can't get more connections."); } } // O(∞)