Beispiel #1
0
 protected void onTcpClientAsyncResultCallback(TCPClientAsyncResultEventArgs e)
 {
     if (tcpClientAsyncResult != null)
     {
         tcpClientAsyncResult(this, e);
     }
 }
Beispiel #2
0
        private void receiveCallback(IAsyncResult ar)
        {
            // Retrieve the state object and the client socket
            // from the asynchronous state object.
            StateObject state  = (StateObject)ar.AsyncState;
            Socket      client = state.workSocket;

            // Read data from the remote device.
            int bytesRead = client.EndReceive(ar);

            if (bytesRead > 0)
            {
                // There might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));

                TCPClientAsyncResultEventArgs result =
                    new TCPClientAsyncResultEventArgs(Encoding.ASCII.GetString(state.buffer, 0, bytesRead),
                                                      tcpClientSocket.Connected);
                onTcpClientAsyncResultCallback(result);

                Console.WriteLine(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));

                // Get the rest of the data.
                client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                    new AsyncCallback(receiveCallback), state);
            }
            else
            {
                // All the data has arrived; put it in response.
                if (state.sb.Length > 1)
                {
                    response = state.sb.ToString();
                }
                // Signal that all bytes have been received.
                receiveDone.Set();
            }
        }
Beispiel #3
0
        private void receiveCallback(IAsyncResult ar)
        {
            // Retrieve the state object and the client socket
            // from the asynchronous state object.
            StateObject state = (StateObject)ar.AsyncState;
            Socket client = state.workSocket;

            // Read data from the remote device.
            int bytesRead = client.EndReceive(ar);

            if (bytesRead > 0)
            {
                // There might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));

                TCPClientAsyncResultEventArgs result =
                    new TCPClientAsyncResultEventArgs(Encoding.ASCII.GetString(state.buffer, 0, bytesRead),
                        tcpClientSocket.Connected);
                onTcpClientAsyncResultCallback(result);

                Console.WriteLine(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));

                // Get the rest of the data.
                client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback(receiveCallback), state);
            }
            else
            {
                // All the data has arrived; put it in response.
                if (state.sb.Length > 1)
                {
                    response = state.sb.ToString();
                }
                // Signal that all bytes have been received.
                receiveDone.Set();

            }
        }
Beispiel #4
0
 protected void onTcpClientAsyncResultCallback(TCPClientAsyncResultEventArgs e)
 {
     if (tcpClientAsyncResult != null)
     {
         tcpClientAsyncResult(this, e);
     }
 }
Beispiel #5
0
 public void SockExceptionHandler(object o, UnhandledExceptionEventArgs args)
 {
     TCPClientAsyncResultEventArgs result = new TCPClientAsyncResultEventArgs("", tcpClientSocket.Connected);
     onTcpClientAsyncResultCallback(result);
 }
Beispiel #6
0
 public void OnTcpClientResultCallback(object o, TCPClientAsyncResultEventArgs e)
 {
 }
Beispiel #7
0
        public void SockExceptionHandler(object o, UnhandledExceptionEventArgs args)
        {
            TCPClientAsyncResultEventArgs result = new TCPClientAsyncResultEventArgs("", tcpClientSocket.Connected);

            onTcpClientAsyncResultCallback(result);
        }