Пример #1
0
        /// <summary>
        /// Set up the server, bind to a socket. Use Start to fully start the server after running this
        /// </summary>
        /// <param name="configuration"></param>
        public static void InitializeServer(ServerConfiguration configuration)
        {
            Configuration = configuration;

            if (peer != null && peer.Status != NetPeerStatus.NotRunning)
            {
                Debug.LogError("cannot start server while already running");
                return;
            }

            _netPeerConfiguration = new NetPeerConfiguration(Configuration.AppIdentifier);
            _netPeerConfiguration.Port = Configuration.ListenPort;
            _netPeerConfiguration.MaximumConnections = Configuration.MaximumConnections;
            _netPeerConfiguration.ReceiveBufferSize = Configuration.ReceiveBuffer;
            _netPeerConfiguration.SendBufferSize = Configuration.SendBuffer;
            connections = new IntDictionary<NetConnection>(Configuration.MaximumConnections);

            //pnet specific things...
            _netPeerConfiguration.AutoFlushSendQueue = false;
            _netPeerConfiguration.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            peer = new NetServer(_netPeerConfiguration);
            tcpServer = new TcpServer();

            peer.Start();
            tcpServer.Start(Configuration.TcpListenPort);
            

            var serverId = connections.Add(null);
            var serverPlayer = new Player();
            serverPlayer.Id = (ushort)serverId;
            Player.Server = serverPlayer;

            GameState.update += Update;
            GameState.lateUpdate += LateUpdate;
        }
Пример #2
0
 public void TestInitialize()
 {
     _server = new TcpServer();
     _server.Start(14000);
     Thread.Sleep(100);
 }