Пример #1
0
        private void HandleReceive(IAsyncResult ar)
        {
            UdpClient receiveClient = (UdpClient)ar.AsyncState;

            try
            {
                IPEndPoint receiveAddr  = null;
                byte[]     receiveBytes = receiveClient.EndReceive(ar, ref receiveAddr);
                if (receiveBytes.Length >= 24)
                {
                    UdpMeshCommon.ProcessBytes(receiveBytes, receiveAddr, callbacks);
                }
            }
            catch (Exception e)
            {
                if (!shutdown)
                {
                    Console.WriteLine("Error receiving: " + e);
                }
            }
            if (!shutdown)
            {
                try
                {
                    receiveClient.BeginReceive(HandleReceive, receiveClient);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error restarting receive: " + e);
                    error = true;
                }
            }
        }
Пример #2
0
 private void HandleRelayMessage(byte[] inputData, Guid serverGuid, IPEndPoint endPoint)
 {
     if (inputData.Length < 64)
     {
         return;
     }
     byte[] cropMessage = new byte[inputData.Length - 40];
     Array.Copy(inputData, 40, cropMessage, 0, cropMessage.Length);
     UdpMeshCommon.ProcessBytes(cropMessage, null, callbacks);
 }
Пример #3
0
 private void HandleReceive(UdpClient receiveClient, bool isv6)
 {
     try
     {
         if (receiveClient.Client.Available == 0)
         {
             return;
         }
         byte[]   buffer = v4buffer;
         EndPoint receiveAddrEndpoint = (EndPoint)anyV4;
         if (isv6)
         {
             buffer = v6buffer;
             receiveAddrEndpoint = (EndPoint)anyV6;
         }
         byte[]     processBytes = buffer;
         int        bytesRead    = receiveClient.Client.ReceiveFrom(buffer, ref receiveAddrEndpoint);
         IPEndPoint receiveAddr  = (IPEndPoint)receiveAddrEndpoint;
         bool       process      = true;
         if (bytesRead >= 24)
         {
             if (process)
             {
                 try
                 {
                     if (!UdpMeshCommon.USE_BUFFERS)
                     {
                         processBytes = new byte[bytesRead];
                         Array.Copy(buffer, 0, processBytes, 0, bytesRead);
                     }
                     UdpMeshCommon.ProcessBytes(processBytes, bytesRead, receiveAddr, callbacks);
                 }
                 catch (Exception e)
                 {
                     DebugLog("Error processing message: " + e);
                 }
             }
         }
     }
     catch (Exception e)
     {
         if (!shutdown)
         {
             Console.WriteLine("Error receiving: " + e);
         }
     }
 }
Пример #4
0
 private void HandleRelayMessage(byte[] inputData, int inputDataLength, Guid serverGuid, IPEndPoint endPoint)
 {
     lock (relayBuffer)
     {
         if (inputDataLength < 64)
         {
             return;
         }
         byte[] relayData = relayBuffer;
         if (!UdpMeshCommon.USE_BUFFERS)
         {
             relayData = new byte[inputDataLength - 40];
         }
         Array.Copy(inputData, 0, relayData, 0, inputDataLength - 40);
         UdpMeshCommon.ProcessBytes(relayData, inputDataLength - 40, null, callbacks);
     }
 }