Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. /*
  2. *The function is getting the messages and reading them from the server/
  3. * input: client Stream
  4. * output: the message from the server
  5. */
  6.  
  7. private string readMessage(NetworkStream playerStream)
  8. {
  9. Byte[] buffer = new Byte[bytessize];
  10. List<byte> listOfBytes = new List<byte>();//Because of null termiend we are using list of bytes so we take the important message
  11. try
  12. {
  13. int byteRead = playerStream.Read(buffer, 0, bytessize);
  14. foreach (int i in Enumerable.Range(0, byteRead))
  15. {
  16. if (!buffer[i].Equals(0))
  17. {
  18. rwl.AcquireReaderLock(Timeout.InfiniteTimeSpan.Milliseconds);
  19. listOfBytes.Add(buffer[i]);
  20. rwl.ReleaseReaderLock();
  21. }
  22.  
  23. }
  24. }
  25. catch{rwl.ReleaseReaderLock();}
  26. return Encoding.UTF8.GetString(listOfBytes.ToArray());//Making into an array of bytes(The real charaters that has there and making in into encoding of utf8(can be also encoding of ascii , In our case it doesn't matter)).
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement