Beispiel #1
0
 private void AcceptConnection()
 {
     _listener.Start();
     for (; ;)
     {
         TcpClient curClient = null;
         Thread.Sleep(1000);
         if (!_running)
         {
             return;
         }
         try
         {
             curClient = _listener.AcceptTcpClient();
             if (curClient != null)
             {
                 // [DBG]
                 Console.WriteLine("[Server] Establishing connection...");
                 NetworkStream stream = curClient.GetStream();
                 stream.ReadTimeout  = 2000;
                 stream.WriteTimeout = 2000;
                 BinaryReader     reader = new BinaryReader(stream);
                 string           data   = reader.ReadString();
                 ClientIdentifier ident  = Newtonsoft.Json.JsonConvert.DeserializeObject <ClientIdentifier>(data);
                 User             user   = new User(curClient, ident);
                 _users.Add(user);
                 Console.WriteLine(string.Format("[Server] Connected with : {0}", user.Identifier.Name));
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine("[Server] X");
             Console.WriteLine(ex.ToString());
         }
     }
 }
Beispiel #2
0
 public User(TcpClient client, ClientIdentifier ident)
 {
     _client = client;
     _ident  = ident;
 }
Beispiel #3
0
 public Client(string name)
 {
     // [DBG]
     _ident = new ClientIdentifier(name, "127.0.0.1");
     Connect();
 }
Beispiel #4
0
 public ClientEvent(ClientIdentifier identifier, ClientEventType type)
 {
     _identifier = identifier;
     _type       = type;
 }