Exemple #1
0
        public void init()
        {
            netServer = new NetServer(ServerConfigurator.netPeerConfig);

            serverController = new ServerController(netServer);
            serverController.StartServer();

            netServer.UPnP.ForwardPort(ServerConfigurator.port, "GServer");


            Console.WriteLine("[SA] Server Started and serving.");
            Console.WriteLine("Unique identifier is " + NetUtility.ToHexString(netServer.UniqueIdentifier));

            // in your separate thread
            while (netServer.MessageReceivedEvent.WaitOne()) // this will block until a message arrives
            {
                NetIncomingMessage msg = netServer.ReadMessage();
                sMessageParseManager.parseMessage(msg, this);
                netServer.Recycle(msg);
            }
        }
Exemple #2
0
        public void init()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("GJABD_GAME");

            config.Port         = 14242;
            config.LocalAddress = IPAddress.Any;
            config.EnableUPnP   = true;
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            //ON PRODUCTION:
            //config.DisableMessageType(NetIncomingMessageType.WarningMessage);

            netServer = new NetServer(config);

            serverController = new ServerController(netServer);
            try
            {
                serverController.StartServer();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            netServer.UPnP.ForwardPort(14242, "GServer");



            Console.WriteLine("[SA] Server Started and serving.");
            Console.WriteLine("Unique identifier is " + NetUtility.ToHexString(netServer.UniqueIdentifier));

            // in your separate thread
            while (netServer.MessageReceivedEvent.WaitOne()) // this will block until a message arrives
            {
                NetIncomingMessage msg = netServer.ReadMessage();
                sMessageParseManager.parseMessage(msg, this);
                netServer.Recycle(msg);
            }
        }