public void ListenForConnections() { Console.WriteLine("Server started. Listening for connections..."); while (isStarted) { TcpClient client = listener.AcceptTcpClient(); NetworkStream ns = client.GetStream(); //Add user ip to server GUI user list this.listBox.BeginInvoke((MethodInvoker) delegate() { listBox.Items.Add(((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString()); }); Console.WriteLine(users.Count); string userName = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString(); Console.WriteLine("Connected to client: " + userName); HandleClientConnection hc = new HandleClientConnection(ns, listLog, userName, this); Thread handleConnection = new Thread(new ThreadStart(hc.ReceiveMessagesFromClient)); handleConnection.Start(); } }
public User(HandleClientConnection hc, string userN) { // client = c; handleClient = hc; userName = userN; }