Beispiel #1
0
        void ServerSocketProc()
        {
            IPEndPoint ipe = new IPEndPoint(IPAddress.Any, port);

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

            try
            {
                serverSocket.Bind(ipe);
                serverSocket.Listen(100);
                Console.WriteLine("Listen {0}", ipe.Port);

                while (true)
                {
                    try
                    {
                        Socket clientSocket = serverSocket.Accept();
                        ClientPeer clientPeer = new ClientPeer(clientSocket);
                        clientPeer.Start();

                        clientListMan.Clean();
                        clientListMan.Add(clientPeer);

                    }
                    catch (SocketException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    catch (System.Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                }
            }
            catch
            {
            }
        }