Exemple #1
0
        public ServerClass(int ServerPort)
        {
            this.Port = ServerPort;
            this.myServerTokenInformation      = new tokenInformation();
            this.myServerTokenInformation.Port = Port;

            this.myClientAccept = new Thread(new ParameterizedThreadStart(this.threadAcceptClients));
            this.myUpdateThread = new Thread(new ParameterizedThreadStart((object o) =>
            {
                tokenInformation myToken = (tokenInformation)o;
                while (myToken.Stop == false)
                {
                    Console.Title = String.Format("Server is running on Port: {0} with {1} Client(s)", myToken.Port, ServerClient.ConnectedClientsCount);
                    Thread.Sleep(10000);
                }
            }));
        }
Exemple #2
0
        private void threadAcceptClients(object myTokenInformation)
        {
            tokenInformation mTI = (tokenInformation)myTokenInformation;

            Socket serverSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);

            serverSocket.Bind(new IPEndPoint(IPAddress.Any, mTI.Port));

            serverSocket.Listen(0);

            while (!mTI.Stop)
            {
                Socket clientSocket = serverSocket.Accept();

                if (clientSocket != null)
                {
                    ServerClient c = new ServerClient(clientSocket);
                    c.Geantwortet += this.Client_Antwort;
                    c.SendDDS();
                }
            }
        }