Beispiel #1
0
        private void ListenToClient(object playerIdObj)
        {
            int playerId;

            if (!(playerIdObj is int))
            {
                return;
            }

            playerId = (int)playerIdObj;
            Address    playerAddress    = playerAddresses[playerId];
            long       ipAddress        = (long)(uint)IPAddress.NetworkToHostOrder((int)IPAddress.Parse(playerAddress.Server).Address);
            IPEndPoint playerIPEndPoint = new IPEndPoint(ipAddress, playerAddress.Port);

            while (playerAddresses.ContainsKey(playerId))
            {
                try
                {
                    byte[] package = server.Receive(ref playerIPEndPoint);
                    IncomingPackagesManager.HandlePackage(package, playerId);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Beispiel #2
0
    public void ReceiveCallback(IAsyncResult ar)
    {
        UdpClient  u = ((UdpState)(ar.AsyncState)).u;
        IPEndPoint e = ((UdpState)(ar.AsyncState)).e;

        byte[] package = u.EndReceive(ar, ref e);
        messageReceived = true;

        IncomingPackagesManager.HandlePackage(package);
    }
Beispiel #3
0
        public void ReceiveCallback(IAsyncResult ar)
        {
            UdpClient  u = ((UdpState)(ar.AsyncState)).u;
            IPEndPoint e = ((UdpState)(ar.AsyncState)).e;

            byte[] package = u.EndReceive(ar, ref e);
            messageReceived = true;

            for (int i = 0; i < package.Length; i++)
            {
                Console.Write(package[i]);
            }
            Console.WriteLine();

            IncomingPackagesManager.HandlePackage(package);
        }