Beispiel #1
0
        //Processing server response
        private void UdpProccessServerResponse()
        {
            try
            {
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0);
                while (true)
                {
                    byte[]         bytes          = udpClient.Receive(ref endPoint);
                    MemoryStream   memoryStream   = new MemoryStream(bytes);
                    Packets.Packet recievedPacket = formatter.Deserialize(memoryStream) as Packets.Packet;

                    switch (recievedPacket.m_PacketType)
                    {
                    case Packets.Packet.PacketType.PictionaryPaint:
                        Packets.PictionaryPaintPacket paintPacket = recievedPacket as Packets.PictionaryPaintPacket;
                        pictionaryForm.UpdatePaintCanvas(paintPacket.XPositions, paintPacket.YPositions, paintPacket.PenColor, paintPacket.SameLine);
                        break;

                    case Packets.Packet.PacketType.PictionaryClearCanvas:
                        pictionaryForm.ClearCanvas();
                        break;
                    }
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Client UDP Read Method Exception: " + e.Message);
            }
        }