Exemplo n.º 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());
         }
     }
 }
Exemplo n.º 2
0
 public User(TcpClient client, ClientIdentifier ident)
 {
     _client = client;
     _ident  = ident;
 }
Exemplo n.º 3
0
 public Client(string name)
 {
     // [DBG]
     _ident = new ClientIdentifier(name, "127.0.0.1");
     Connect();
 }
Exemplo n.º 4
0
 public ClientEvent(ClientIdentifier identifier, ClientEventType type)
 {
     _identifier = identifier;
     _type       = type;
 }