usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Threading.Tasks;namespaceServer{publicclassTcpChatServer{TcpListenerserverSocket;publicvoidStart(stringipAddress,intport){try{serverSocket=newTcpListener(IPAddress.Parse(ipAddress),port);serverSocket.Start();LogSingleton.Instance.Log+="Server started.\n";Task.Run(()=>Listen(serverSocket));LogSingleton.Instance.Log+="Waiting for connections...\n";}catch(Exceptionex){Console.WriteLine(ex.Message);}}privatevoidListen(TcpListenerlistener){while(true){ClientConnectioncc=newClientConnection(listener);LogSingleton.Instance.ConnectedClients.Add(cc);}}publicvoidStop(){serverSocket.Stop();LogSingleton.Instance.Log+="Server stopped\n";}publicvoidSendMessage(stringmessage){foreach(ClientConnectionclientinLogSingleton.Instance.ConnectedClients)client.StreamWriter.WriteLine(message);}}}