示例#1
0
 private static void WaitForServerMessage()
 {
     if (IsConnected)
     {
         var socketArgs = SocketArgsPool.GetReceiveArg();
         socketArgs.Completed += ReceiveFromServerCompleted;
         var willFireCallback = TcpClient.Client.ReceiveAsync(socketArgs);
         if (!willFireCallback)
         {
             ReceiveFromServerCompleted(TcpClient.Client, socketArgs);
         }
     }
 }
        public void SendBytes(byte[] bytes)
        {
            if (socketOut.Connected)
            {
                if (Encryptor != null)
                {
                    bytes = Encryptor.EncryptBytes(bytes);
                }
                var messageHeader = new byte[]
                {
                    (byte)(bytes.Length % 10000000000 / 100000000),
                    (byte)(bytes.Length % 100000000 / 1000000),
                    (byte)(bytes.Length % 1000000 / 10000),
                    (byte)(bytes.Length % 10000 / 100),
                    (byte)(bytes.Length % 100),
                };

                bytes = messageHeader.Concat(bytes).ToArray();
                var socketArgs = SocketArgsPool.GetSendArg();
                socketArgs.SetBuffer(bytes, 0, bytes.Length);
                socketOut.SendAsync(socketArgs);
            }
        }