Ejemplo n.º 1
0
        private void DoChat()
        {
            Byte[] clientBytes = new byte[10000];
            Byte[] sendBytes;
            String clientMsg;

            while (true)
            {
                try
                {
                    NetworkStream clientStream = clientSocket.GetStream();
                    clientStream.Read(clientBytes, 0, clientBytes.Length);
                    clientMsg = Encoding.ASCII.GetString(clientBytes);
                    clientMsg = clientMsg.Substring(0, clientMsg.IndexOf("#") + 1);
                    Console.WriteLine("Received from Client: " + clientMsg);
                    sendBytes = Server.PrepareMsg(Convert.ToString(clientNum), clientMsg, true);
                    Server.Broadcast(sendBytes);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }