Exemplo n.º 1
0
        protected internal void RemoveConnection(string id)
        {
            // we obtain by id a closed connection
            ClObject client = clients.FirstOrDefault(c => c.Id == id);

            // and delete it from the list of connections
            if (client != null)
            {
                clients.Remove(client);
            }
        }
Exemplo n.º 2
0
        // listening for incoming connections
        protected internal void Listen()
        {
            try
            {
                tcpListener = new TcpListener(IPAddress.Any, 1000);
                tcpListener.Start();
                Console.WriteLine("Server is started. Waiting for connections...");

                while (true)
                {
                    TcpClient tcpClient = tcpListener.AcceptTcpClient();

                    ClObject clientObject = new ClObject(tcpClient, this);
                    Thread   clientThread = new Thread(new ThreadStart(clientObject.Process));
                    clientThread.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Disconnect();
            }
        }
Exemplo n.º 3
0
        List <ClObject> clients = new List <ClObject>(); // all connections

        protected internal void AddConnection(ClObject clientObject)
        {
            clients.Add(clientObject);
        }