static void Main(string[] args) { TcpListener serverSocket = new TcpListener(8888); TcpClient clientSocket = default(TcpClient); serverSocket.Start(); Console.WriteLine("Server Started..."); while (true) { clientSocket = serverSocket.AcceptTcpClient(); byte[] bytesFrom = new byte[10025]; string dataFromClient = null; NetworkStream networkStream = clientSocket.GetStream(); networkStream.Read(bytesFrom, 0, 10000); dataFromClient = Encoding.ASCII.GetString(bytesFrom); dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$")); clientList.Add(dataFromClient, clientSocket); broadcast(dataFromClient + " Joined the Chat", dataFromClient, false); Console.WriteLine(dataFromClient + " Joined the Chat Room"); handleClient client = new handleClient(); client.startClient(clientSocket, dataFromClient, clientList); } }
static void Main(string[] args) { TcpClient clientSocket = default(TcpClient); TcpListener serverSocket = new TcpListener(8888); int count; serverSocket.Start(); Console.WriteLine("Chat Server Started ..."); count = 0; while (true) { count++; clientSocket = serverSocket.AcceptTcpClient(); byte[] byteFrom = new byte[10025]; string ClientData = null; NetworkStream networkStream = clientSocket.GetStream(); networkStream.Read(byteFrom, 0, (int)clientSocket.ReceiveBufferSize); ClientData = System.Text.Encoding.ASCII.GetString(byteFrom); ClientData = ClientData.Substring(0, ClientData.IndexOf("$")); Client_List.Add(ClientData, clientSocket); Broadcast($"{ClientData} Joined", ClientData, false); Console.WriteLine($"{ClientData} joined this chat!!!"); handleClient client = new handleClient(); client.startClient(clientSocket, ClientData, Client_List); } clientSocket.Close(); serverSocket.Stop(); Console.WriteLine("Exiting Chat Server."); Console.ReadLine(); }