private void HandleClientComm(object client)
        {
            TcpClient tcpClient = (TcpClient)client;
               NetworkStream clientStream = tcpClient.GetStream();

               byte[] message = new byte[2048];
               int bytesRead;

               while (true)
               {
               bytesRead = 0;

               try
               {
                   //blocks until a client sends a message
                   bytesRead = clientStream.Read(message, 0, 2048);
               }
               catch
               {
                   //a socket error has occured
                   break;
               }

               if (bytesRead == 0)
               {
                   //the client has disconnected from the server
                   break;
               }

               //message has successfully been received
               UnicodeEncoding encoder = new UnicodeEncoding();
               System.Diagnostics.Debug.WriteLine(encoder.GetString(message, 0, bytesRead));
               Message msg = new Message(encoder.GetString(message, 0, bytesRead));
               OnMessageRecieved(msg);
               //String text = encoder.GetString(message, 0, bytesRead);
               break;
               }

               tcpClient.Close();
        }
 private void ListenForBroadcast()
 {
     IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, port);
        while (true)
        {
       Byte [] message = this.udpListener.Receive(ref ep);
       UnicodeEncoding encoder = new UnicodeEncoding();
       System.Diagnostics.Debug.WriteLine(encoder.GetString(message, 0, message.Length));
       Message msg = new Message(encoder.GetString(message, 0, message.Length));
       OnBroadcastRecieved(msg, ep.ToString());
        }
 }
Exemple #3
0
 public static void handlethisshit(Message msg)
 {
 }