コード例 #1
0
ファイル: Server.cs プロジェクト: caddeo/Auktionshuset
        public void Run()
        {
            _broadcaster = new Broadcaster();

            IPAddress ip = IPAddress.Parse(_servername);
            TcpListener listener = new TcpListener(ip, _port);

            /* Gør så at serveren kan skrive input*/
            Thread serverInputThread = new Thread(HandleInput);
            serverInputThread.Start();

            _running = true;

            listener.Start();

            Console.WriteLine("Skriv \'new\' for at starte en ny auktion.");

            while (_running)
            {
                System.Console.WriteLine("Server klar til bruger");
                /* En socket forbinder*/
                Socket clientSocket = listener.AcceptSocket();

                /* Lav en ny client handler til forbindelsen */
                ClientHandler handler = new ClientHandler(clientSocket, _broadcaster);
                handler.SetAuction(_auction);

                /* Start det i en ny tråd */
                Thread clientThread = new Thread(handler.RunClient);

                /* Start trådene */
                clientThread.Start();
            }
        }