Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. TcpClient connection = new TcpClient(hostname, port);
  2. NetworkStream stream = connection.GetStream();
  3.  
  4. thread = new Thread(ProcessStream);
  5. thread.Start(stream);
  6.  
  7. private void ProcessStream(object stream)
  8. {
  9. Stream source = (NetworkStream)stream;
  10. byte[] line;
  11. int count;
  12. const int capacity = 300;
  13. ReadState readState;
  14. while ((readState = ReadStreamLine(source, out line, out count, capacity)) != ReadState.EOF && _stopFeed == false)
  15. {
  16. if (readState != ReadState.Error && count > 4)
  17. {
  18. byte[] line1 = new byte[count];
  19. Array.Copy(line, line1, count);
  20. Process(line1); // return ignored in stream mode
  21. }
  22. else
  23. {
  24. ReadFail(line, count);
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement