V1/Cet.Develop.WP.IO/Net/SocketClient.cs
/// <summary>
/// Receive data from the server using the established socket connection
/// </summary>
/// <returns>The data received from the server, when no error was thrown</returns>
Receive data from the server using the established socket connection
Receive data from the server using the established socket connection
public byte[] Receive(int timeout = TIMEOUT_MILLISECONDS)
        {
            string response = "Operation Timeout";
            byte[] buffer = new byte[0];
            if (_socket != null)
            {
                SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
                socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint;
                socketEventArg.SetBuffer(
                    new Byte[MaxBufferSize],
                    0,
                    MaxBufferSize);
                socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
                {
                    if (e.SocketError == SocketError.Success)
                    {
                        response = string.Empty;
                        buffer = new byte[e.BytesTransferred];
                        Buffer.BlockCopy(
                            e.Buffer,
                            e.Offset,
                            buffer,
                            0,
                            buffer.Length);
                    }
                    else
                    {
                        response = e.SocketError.ToString();
                    }
                    _clientDone.Set();
                });
                _clientDone.Reset();
                _socket.ReceiveAsync(socketEventArg);
                _clientDone.WaitOne(timeout);
            }
            else
            {
                response = "Socket is not initialized";
            }
            this.LastError = response;
            return buffer;
        }
public byte [ ] Receive ( int timeout = TIMEOUT_MILLISECONDS ) { string response = " " ; byte [ ] buffer = new byte [ 0 ] ; if ( _socket != null ) { SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs ( ) ; socketEventArg . RemoteEndPoint = _socket . RemoteEndPoint ; socketEventArg . SetBuffer ( new Byte [ MaxBufferSize ] , 0 , MaxBufferSize ) ; socketEventArg . Completed += new EventHandler < SocketAsyncEventArgs > ( delegate ( object s , SocketAsyncEventArgs e ) { if ( e . SocketError == SocketError . Success ) { response = string . Empty ; buffer = new byte [ e . BytesTransferred ] ; Buffer . BlockCopy ( e . Buffer , e . Offset , buffer , 0 , buffer . Length ) ; } else { response = e . SocketError . ToString ( ) ; } _clientDone . Set ( ) ; } ) ; _clientDone . Reset ( ) ; _socket . ReceiveAsync ( socketEventArg ) ; _clientDone . WaitOne ( timeout ) ; } else { response = " " ; } this . LastError = response ; return buffer ; }
Receive data from the server using the established socket connection
Receive data from the server using the established socket connection
// We are receiving over an established socket connection // Create SocketAsyncEventArgs context object // Setup the buffer to receive the data // Inline event handler for the Completed event. // Note: This even handler was implemented inline in order to make this method self-contained. // Retrieve the data from the buffer // Sets the state of the event to nonsignaled, causing threads to block // Make an asynchronous Receive request over the socket // Block the UI thread for a maximum of TIMEOUT_MILLISECONDS milliseconds. // If no response comes back within this time then proceed
The data received from the server, when no error was thrown
The data received from the server when no error was thrown
timeout
int