Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. public static void SendMessage(string message) {
  2. //Send message
  3. byte[] bytes = Encoding.UTF8.GetBytes(message);
  4. NetworkStream stream = Client.GetStream();
  5. stream.Write(bytes, 0, bytes.Length);
  6. }
  7.  
  8. public static string ReceiveMessage() {
  9. byte[] bytes = new byte[ByteSize];
  10. NetworkStream stream = Client.GetStream();
  11. stream.Read(bytes, 0, ByteSize);
  12. return cleanMessage(bytes);
  13. }
  14. private static string cleanMessage(byte[] bytes) {
  15. string message = Encoding.UTF8.GetString(bytes);
  16.  
  17. string messageToPrint = null;
  18. foreach (var nullChar in message) {
  19. if (nullChar != '\0') {
  20. messageToPrint += nullChar;
  21. }
  22. }
  23. return messageToPrint;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement