예제 #1
0
 public void Drawing_listener()
 {
     while (true)
     {
         IPEndPoint client         = new IPEndPoint(IPAddress.Any, new_port);
         byte[]     bytes          = listener2.Receive(ref client);
         string     client_command = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
         if (client_command.Length == 1)
         {
             color = Int32.Parse(client_command);
         }
         else if (client_command != "disconnect" && client_command != "connect")
         {
             string[]    tokens = client_command.Split(',');
             Point       start  = new Point(Int32.Parse(tokens[0]), Int32.Parse(tokens[1]));
             Point       end    = new Point(Int32.Parse(tokens[2]), Int32.Parse(tokens[3]));
             DrawingData data   = null;
             for (int i = 0; i < CLIENT_MAX; i++)
             {
                 if (ClientList[i].ip.Equals(client.Address) && ClientList[i].port.Equals(client.Port))
                 {
                     data = new DrawingData(ClientList[i].ID, start, end, color);
                     break;
                 }
             }
             queue.Enqueue(data);
         }
     }
 }
예제 #2
0
 public void Client_sender()
 {
     while (true)
     {
         DrawingData tmp = new DrawingData();
         while (!queue.TryDequeue(out tmp))
         {
             ;
         }
         string server_message = tmp.LineStart.X.ToString() + "," + tmp.LineStart.Y.ToString() + "," + tmp.LineEnd.X.ToString() + "," + tmp.LineEnd.Y.ToString() + "," + tmp.color.ToString();
         char[] tab            = server_message.ToCharArray();
         byte[] mes            = Encoding.ASCII.GetBytes(tab);
         for (int i = 0; i < CLIENT_MAX; i++)
         {
             if (ClientList[i].ID != -1)
             {
                 IPEndPoint client = new IPEndPoint(ClientList[i].ip, ClientList[i].port);
                 listener.Send(mes, mes.Length, client);
             }
         }
     }
 }