Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void ReceiveCallback(IAsyncResult ar)
- {
- try
- {
- // 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));
- SFC sfc = new SFC();
- sfc.msg("HI!");
- // 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)
- {
- SFC sfc = new SFC();
- sfc.msg(state.sb.ToString());
- }
- // Signal that all bytes have been received.
- SFC.receiveDone.Set();
- }
- }
- catch (Exception e)
- {
- SFC sfc = new SFC();
- sfc.msg(e.ToString());
- }
- }
Add Comment
Please, Sign In to add comment