Esempio n. 1
0
        public OneClient(List <OneClient> _users, TcpClient _connection, StreamReader _reader, String _nick, String _room, ServerForm _serverForm)
        {
            Console.WriteLine("New Client");
            connection = _connection;
            reader     = _reader;
            nick       = _nick;
            room       = _room;
            ServerForm       serverForm = _serverForm;
            List <OneClient> users      = _users;

            writer = new StreamWriter(connection.GetStream());

            messages = new Thread(() => {
                while (true)
                {
                    try {
                        Console.WriteLine("Send to ALL");
                        serverForm.SendToAllUsers(users, reader.ReadLine(), nick);
                    }
                    catch {
                        Console.WriteLine("REMOVE THIS USER");
                        serverForm.RemoveUser(this);
                    }
                }
            });
            messages.Start();
        }
Esempio n. 2
0
        public ChatServer(string host, string port, ServerForm serverForm)
        {
            var ipe = new IPEndPoint(IPAddress.Parse(host), Int16.Parse(port));

            tcpListener = new TcpListener(ipe);
            clients     = new Dictionary <NetworkStream, String>();
            form        = serverForm;
        }