Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *The function is getting the messages and reading them from the server/
- * input: client Stream
- * output: the message from the server
- */
- private string readMessage(NetworkStream playerStream)
- {
- Byte[] buffer = new Byte[bytessize];
- List<byte> listOfBytes = new List<byte>();//Because of null termiend we are using list of bytes so we take the important message
- try
- {
- int byteRead = playerStream.Read(buffer, 0, bytessize);
- foreach (int i in Enumerable.Range(0, byteRead))
- {
- if (!buffer[i].Equals(0))
- {
- rwl.AcquireReaderLock(Timeout.InfiniteTimeSpan.Milliseconds);
- listOfBytes.Add(buffer[i]);
- rwl.ReleaseReaderLock();
- }
- }
- }
- catch{rwl.ReleaseReaderLock();}
- 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)).
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement