Advertisement
user366312

ClientProgram.cs

May 4th, 2019
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using MyClientServerLib;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Net.Sockets;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11.  
  12. namespace MyClientProgram
  13. {
  14.     class ClientProgram
  15.     {
  16.         static string clientID = string.Empty;
  17.         static string otherClientID = string.Empty;
  18.  
  19.         #region main
  20.         static void Main(string[] args)
  21.         {
  22.             Console.Title = "Client 1";
  23.  
  24.             string host = "localhost";
  25.             int port = 2000;
  26.  
  27.             ClientClass thisClient = new ClientClass(host, port);
  28.             thisClient.Connect();
  29.             thisClient.SendIdToServer();
  30.  
  31.             try
  32.             {
  33.                 // Read in a secong thread.
  34.                 // Because, server will send very few messages.
  35.                 Thread thread = new Thread(delegate()
  36.                 {
  37.                     ClientClass.ReadFromServer(thisClient);
  38.                 });
  39.                 thread.Start();
  40.  
  41.                 // Write in the main thread
  42.                 ClientClass.WriteToServer(thisClient);
  43.             }
  44.             catch
  45.             {
  46.                 thisClient.Disconnect();
  47.             }
  48.         }
  49.         #endregion
  50.  
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement