Server Setup

        static void Main(string[] args)
            //1. Create a new server container.
            ServerConnectionContainer serverConnectionContainer = ConnectionFactory.CreateServerConnectionContainer(1234, false);
            //2. Apply some settings
            serverConnectionContainer.AllowUDPConnections = true;
            //3. Set a delegate which will be called if we receive a connection
            serverConnectionContainer.ConnectionEstablished += ServerConnectionContainer_ConnectionEstablished;
            //4. Set a delegate which will be called if we lose a connection
            serverConnectionContainer.ConnectionLost += ServerConnectionContainer_ConnectionLost;
            //4. Start listening on port 1234


        private static void ServerConnectionContainer_ConnectionLost(Connection connection, ConnectionType connectionType, CloseReason closeReason)
            Console.WriteLine($"Connection {connection.IPRemoteEndPoint} {connectionType} lost. {closeReason}");

        private static void ServerConnectionContainer_ConnectionEstablished(Connection connection, ConnectionType connectionType)
            Console.WriteLine($"{connectionType} Connection received {connection.IPRemoteEndPoint}.");

After “StartTCPListener();” the Server is up and running. The TCPListener is also in charge of the UDP connections. The property “AllowUDPConnections” indicates whether the server is going to accept incomming UDP connections.


Hinterlasse einen Kommentar

Please Login to comment
Notify of