private void SendMessage(PeerMessage message, CustomConnection connection)
        {
            byte[] b = message.Encode();
            encryptor.Encrypt(b);
            IAsyncResult result = connection.BeginSend(b, 0, b.Length, null, null);

            if (!result.AsyncWaitHandle.WaitOne(5000, true))
            {
                throw new Exception("Message didn't send correctly");
            }
            connection.EndSend(result);
        }
示例#2
0
 public static void Send(CustomConnection connection, byte[] buffer, int offset, int count)
 {
     while (count > 0)
     {
         var r = connection.BeginSend(buffer, offset, count, null, null);
         if (!r.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(4)))
         {
             throw new Exception("Could not send required data");
         }
         int transferred = connection.EndSend(r);
         if (transferred == 0)
         {
             throw new Exception("The socket was gracefully killed");
         }
         offset += transferred;
         count  -= transferred;
     }
 }
示例#3
0
 private void SendMessage(PeerMessage message, CustomConnection connection)
 {
     byte[] b = message.Encode();
     encryptor.Encrypt(b);
     IAsyncResult result = connection.BeginSend(b, 0, b.Length, null, null);
     if (!result.AsyncWaitHandle.WaitOne(5000, true))
         throw new Exception("Message didn't send correctly");
     connection.EndSend(result);
 }
示例#4
0
 public static void Send(CustomConnection connection, byte[] buffer, int offset, int count)
 {
     while (count > 0) {
         var r = connection.BeginSend (buffer, offset, count, null, null);
         if (!r.AsyncWaitHandle.WaitOne (TimeSpan.FromSeconds (4)))
             throw new Exception ("Could not send required data");
         int transferred = connection.EndSend (r);
         if (transferred == 0)
             throw new Exception ("The socket was gracefully killed");
         offset += transferred;
         count -= transferred;
     }
 }