Guest User

Untitled

a guest
Jul 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. private static void ReceiveCallback(IAsyncResult ar)
  2. {
  3. try
  4. {
  5. // Retrieve the state object and the client socket
  6. // from the asynchronous state object.
  7. StateObject state = (StateObject)ar.AsyncState;
  8. Socket client = state.workSocket;
  9. // Read data from the remote device.
  10. int bytesRead = client.EndReceive(ar);
  11. if (bytesRead > 0)
  12. {
  13. // There might be more data, so store the data received so far.
  14. state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
  15.  
  16. SFC sfc = new SFC();
  17. sfc.msg("HI!");
  18.  
  19. // Get the rest of the data.
  20. client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
  21. new AsyncCallback(ReceiveCallback), state);
  22. }
  23. else
  24. {
  25. // All the data has arrived; put it in response.
  26. if (state.sb.Length > 1)
  27. {
  28. SFC sfc = new SFC();
  29. sfc.msg(state.sb.ToString());
  30. }
  31. // Signal that all bytes have been received.
  32. SFC.receiveDone.Set();
  33.  
  34. }
  35. }
  36. catch (Exception e)
  37. {
  38. SFC sfc = new SFC();
  39.  
  40. sfc.msg(e.ToString());
  41. }
  42. }
Add Comment
Please, Sign In to add comment