V1/Cet.Develop.WP.IO/Net/SocketClient.cs
/// <summary>
/// Send the given data to the server using the established connection
/// </summary>
/// <param name="data">The data to send to the server</param>
/// <returns>True when the sending succeeded</returns>
Send the given data to the server using the established connection
Send the given data to the server using the established connection
public bool Send(
            IEnumerable<byte> data,
            int timeout = TIMEOUT_MILLISECONDS)
        {
            string response = "Operation Timeout";
            if (_socket != null)
            {
                SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
                socketEventArg.RemoteEndPoint = _socket.RemoteEndPoint;
                socketEventArg.UserToken = null;
                socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
                {
                    response = e.SocketError.ToString();
                    _clientDone.Set();
                });
                var buffer = data.ToArray();
                socketEventArg.SetBuffer(
                    buffer,
                    0,
                    buffer.Length);
                _clientDone.Reset();
                _socket.SendAsync(socketEventArg);
                _clientDone.WaitOne(timeout);
            }
            else
            {
                response = "Socket is not initialized";
            }
            this.LastError = response;
            return string.IsNullOrEmpty(response);
        }
public bool Send ( IEnumerable < byte > data , int timeout = TIMEOUT_MILLISECONDS ) { string response = " " ; if ( _socket != null ) { SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs ( ) ; socketEventArg . RemoteEndPoint = _socket . RemoteEndPoint ; socketEventArg . UserToken = null ; socketEventArg . Completed += new EventHandler < SocketAsyncEventArgs > ( delegate ( object s , SocketAsyncEventArgs e ) { response = e . SocketError . ToString ( ) ; _clientDone . Set ( ) ; } ) ; var buffer = data . ToArray ( ) ; socketEventArg . SetBuffer ( buffer , 0 , buffer . Length ) ; _clientDone . Reset ( ) ; _socket . SendAsync ( socketEventArg ) ; _clientDone . WaitOne ( timeout ) ; } else { response = " " ; } this . LastError = response ; return string . IsNullOrEmpty ( response ) ; }
Send the given data to the server using the established connection
Send the given data to the server using the established connection
// We are re-using the _socket object that was initialized in the Connect method // Create SocketAsyncEventArgs context object // Set properties on context object // Inline event handler for the Completed event. // Note: This event handler was implemented inline in order to make this method self-contained. // Unblock the thread // Add the data to be sent into the buffer // Sets the state of the event to nonsignaled, causing threads to block // Make an asynchronous Send request over the socket // Block the thread for a maximum of TIMEOUT_MILLISECONDS milliseconds. // If no response comes back within this time then proceed
True when the sending succeeded
True when the sending succeeded
data
IEnumerable<byte>
The data to send to the server
The data to send to the server
timeout
int