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