Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Title = "Servidor";

            serverSocket = new TcpListener(IPAddress.Any, 7777);
            clientSocket = default(Socket);
            serverSocket.Start();

            while (true)
            {
                Console.WriteLine("Esperando conexões...");
                clientSocket = serverSocket.AcceptSocket();
                Console.WriteLine("Conectado!");
                int i = 0;
                for (i = 0; i < maxClientsCount; i++)
                {
                    if (clients[i] == null)
                    {
                        (clients[i] = new handleClient()).startClient(clientSocket, clients);
                        break;
                    }
                }

                if (i == maxClientsCount)
                {
                    StreamWriter ots = new StreamWriter(new NetworkStream(clientSocket));
                    ots.AutoFlush = true;
                    ots.WriteLine("*** Servidor Cheio ***");
                    ots.Close();
                    clientSocket.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public void startClient(Socket inClientSocket, handleClient[] clients)
        {
            this.clientSocket = inClientSocket;
            this.clients = clients;
            this.maxClientsCount = clients.Length;

            Thread ctThread = new Thread(doChat);
            ctThread.Start();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            serverSocket = new TcpListener(IPAddress.Any, 7777);
            clientSocket = default(Socket);
            serverSocket.Start();

            while (true) {
                Console.WriteLine("Esperando a conexion...");
                clientSocket = serverSocket.AcceptSocket();
                Console.WriteLine("Conexion!");
                int i = 0;
                for (i = 0; i < maxClientsCount; i++) {
                    if (clients[i] == null) {
                        (clients[i] = new handleClient()).startClient(clientSocket, clients);
                        break;
                    }
                }

                if (i== maxClientsCount) {
                    StreamWriter ots = new StreamWriter(new NetworkStream(clientSocket));
                    ots.AutoFlush = true;
                    ots.WriteLine("*** Servidor lleno ***");
                    ots.Close();
                    clientSocket.Close();
                }
            }
        }