コード例 #1
0
        private void ReceiveMulticastPacketsLoop()
        {
            while (IsConnected)
            {
                var availableBytes = udpClient.Available;
                if (availableBytes != 0)
                {
                    var senderEndPoint = new IPEndPoint(IPAddress.Any, 1);
                    var buffer         = udpClient.Receive(ref senderEndPoint);

                    if (senderEndPoint == multicastEndPoint && OnReceiveUdpPacket != null)
                    {
                        OnReceiveUdpPacket(PacketConverter.ToPacket <TServerPacket>(buffer));
                    }
                }
            }
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: NiklasVd/Biocell
        private TClientPacket ReceivePacket(ClientConnection clientConnection)
        {
            var receivedBytes = clientConnection.socket.Receive(clientConnection.packetReceivingBuffer);

            if (receivedBytes == 0)
            {
                DisconnectClient(clientConnection.connectionId);
                Console.WriteLine("Kicked client: 0 bytes received");

                return(default(TClientPacket));
            }
            else
            {
                var packetBuffer = new byte[receivedBytes];
                Buffer.BlockCopy(clientConnection.packetReceivingBuffer, 0, packetBuffer, 0, receivedBytes);

                return(PacketConverter.ToPacket <TClientPacket>(packetBuffer));
            }
        }
コード例 #3
0
        private TServerPacket ReceivePacket()
        {
            lock (packetReceivingLock)
            {
                var receivedBytes = socket.Receive(packetReceivingBuffer);

                if (receivedBytes == 0)
                {
                    Disconnect();
                    Console.WriteLine("Disconnected client: 0 bytes received");

                    return(default(TServerPacket));
                }
                else
                {
                    var packetBuffer = new byte[receivedBytes];
                    Buffer.BlockCopy(packetReceivingBuffer, 0, packetBuffer, 0, receivedBytes);

                    return(PacketConverter.ToPacket <TServerPacket>(packetBuffer));
                }
            }
        }