Advertisement
kolya5544

Untitled

Sep 7th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. class Client
  2.     {
  3.         public StreamWriter sw;
  4.         public StreamReader sr;
  5.         public TcpClient tcp;
  6.  
  7.         /// <summary>
  8.         /// Establishes a connection to a server and completes a handshake
  9.         /// </summary>
  10.         public Client()
  11.         {
  12.             try
  13.             {
  14.                 tcp = new TcpClient("127.0.0.1", 55415);
  15.                 NetworkStream ns = tcp.GetStream();
  16.                 sw = new StreamWriter(ns);
  17.                 sw.AutoFlush = true;
  18.                 sr = new StreamReader(ns);
  19.                 tcp.ReceiveTimeout = 3000;
  20.                 tcp.SendTimeout = 3000;
  21.                 string answ = sr.ReadLine().Trim();
  22.                 if (answ == "hand")
  23.                 {
  24.                     Thread.Sleep(100);
  25.                     sw.WriteLine("shake");
  26.                     //From now on, the connection is considered to be established, and the server is awaiting for a cmd
  27.                 }
  28.             } catch
  29.             {
  30.  
  31.             }
  32.         }
  33.        
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement