Пример #1
0
 private void OnSending()
 {
     try
     {
         if (sendQueue.Count == 0 || !IsConnected)
         {
             isSending = false;
             return;
         }
         byte[] buffer = sendQueue.Dequeue();
         //设置消息发送异步对象的发送数据缓冲区数据
         byte[] message = Handler.ProcessWrite(buffer);
         sendEventArgs.SetBuffer(message, 0, message.Length);
         //开启异步发送
         bool result = ClientSocket.SendAsync(sendEventArgs);
         //是否挂起
         if (!result)
         {
             ProcessSend(sendEventArgs);
         }
     }
     catch (Exception e)
     {
         CloseClientSocket(sendEventArgs);
     }
 }