예제 #1
0
        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();
            }
        }
예제 #2
0
 public User(HandleClientConnection hc, string userN)
 {
     //    client = c;
     handleClient = hc;
     userName     = userN;
 }