Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Client
- {
- public StreamWriter sw;
- public StreamReader sr;
- public TcpClient tcp;
- /// <summary>
- /// Establishes a connection to a server and completes a handshake
- /// </summary>
- public Client()
- {
- try
- {
- tcp = new TcpClient("127.0.0.1", 55415);
- NetworkStream ns = tcp.GetStream();
- sw = new StreamWriter(ns);
- sw.AutoFlush = true;
- sr = new StreamReader(ns);
- tcp.ReceiveTimeout = 3000;
- tcp.SendTimeout = 3000;
- string answ = sr.ReadLine().Trim();
- if (answ == "hand")
- {
- Thread.Sleep(100);
- sw.WriteLine("shake");
- //From now on, the connection is considered to be established, and the server is awaiting for a cmd
- }
- } catch
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement