Guest User

Untitled

a guest
Jul 17th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.Net.Sockets;
  8. using System.Threading;
  9.  
  10. namespace Client_ServerChat
  11. {
  12.     class Klient
  13.     {
  14.         TcpClient klient;
  15.  
  16.         public Klient()
  17.         {
  18.             klient = new TcpClient();
  19.  
  20.             try
  21.             {
  22.                 klient.Connect("localhost", 8001);
  23.  
  24.                 NetworkStream stream = klient.GetStream();
  25.  
  26.                 while(true)
  27.                 {
  28.                     byte[] bytes = new byte[klient.ReceiveBufferSize];
  29.                     stream.Read(bytes, 0, (int)klient.ReceiveBufferSize);
  30.                     string returndata = Encoding.UTF8.GetString(bytes);
  31.  
  32.                     if(returndata.Length > 0)
  33.                         Console.WriteLine("This is what the host returned to you: " + returndata);
  34.  
  35.                     Thread.Sleep(300);
  36.                 }
  37.             }
  38.             catch(Exception e)
  39.             {
  40.                 Console.WriteLine(e);
  41.             }
  42.         }  
  43.     }
  44. }
Add Comment
Please, Sign In to add comment