Exemple #1
0
        public void ReadCallback()
        {
            XClient xclient = new XClient();

            while (true)
            {
                int length = udpServer.ReceiveFrom(receiveBuffer, ref remoteEndpoint);

                byte[] tempBuffer = new byte[length];

                Array.Copy(receiveBuffer, 0, tempBuffer, 0, length); // create a properly sized buffer :)

                xclient.Decode(tempBuffer);
            }

            //UdpClient listener = (UdpClient) Ar.AsyncState;
            //byte[] receivedBytes = listener.EndReceive(Ar, ref remoteEP);

            //// The assumption is remoteEP updates to the sending ip (XBOX)

            //XClient xclient = new XClient(listener, remoteEP);

            //Logger.Info("Adding new client (" + xclient.Client.LocalEndPoint + ") to dictionary!");

            //bool result = xClientDictionary.TryAdd(xclient, remoteEP);

            //if (result)
            //{
            //    xclient.Decode(receivedBytes);
            //}
            //else
            //{
            //    Logger.Warn("Server attempted to add duplicate client to " + xClientDictionary);
            //}
        }
Exemple #2
0
        public void ReadCallback(IAsyncResult Ar)
        {
            UdpClient listener = (UdpClient)Ar.AsyncState;

            byte[] receivedBytes = listener.EndReceive(Ar, ref remoteEP);

            // The assumption is remoteEP updates to the sending ip (XBOX)

            XClient client = new XClient(listener, remoteEP);

            Console.WriteLine("XSERVER: Adding new client with an IPv4 Address " + client.Client.Client.LocalEndPoint + " to dictionary!");

            bool result = XClientDictionary.TryAdd(client, remoteEP);

            Console.WriteLine("XSERVER: Result was " + result + "!");

            if (result)
            {
                client.Decode(receivedBytes);
            }
            else
            {
                Console.WriteLine("Server attempted to add duplicate client to " + XClientDictionary);
            }
        }