Exemple #1
0
        internal BaseModel SendRequest(BaseModel baseModel)
        {
            if (this.connected)
            {
                // Create a buffer to send.
                Byte[] sendBuffer = baseModel.ObjectToByteArray();

                // Prepare arguments for send/receive operation.
                SocketAsyncEventArgs dataTransferArgs = new SocketAsyncEventArgs();
                dataTransferArgs.SetBuffer(sendBuffer, 0, sendBuffer.Length);
                dataTransferArgs.UserToken      = this.clientSocket;
                dataTransferArgs.RemoteEndPoint = this.hostEndPoint;
                dataTransferArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(OnSend);

                // Start sending asyncronally.
                clientSocket.SendAsync(dataTransferArgs);

                // Wait for the send/receive completed.
                AutoResetEvent.WaitAll(autoSendReceiveEvents);

                // Return data from SocketAsyncEventArgs buffer.
                return(BaseModel.ByteArrayToObject(dataTransferArgs.Buffer));// (completeArgs.Buffer, completeArgs.Offset, completeArgs.BytesTransferred);
            }
            return(null);
        }