/// <summary> /// Starts the game server. /// </summary> protected virtual void StartListening() { if (useNetworkManager) { DontDestroyOnLoad(gameObject); var networkManager = NetworkManager.singleton as MasterServerNetworkManager; Assert.IsTrue(networkManager != null, "A Master Server Network Manager was not found."); networkManager.gameServer = this; networkManager.networkAddress = gameServerIp; networkManager.networkPort = gameServerPort; networkManager.StartServer(); NetworkServer.RegisterHandler(GameServerNetworkProtocol.RequestGameServerRegistration, OnGameServerRegistrationRequested); NetworkServer.RegisterHandler(BaseServerNetworkProtocol.SendPlayerData, OnPlayerInfoReceived); } else { webGLServer.SetNetworkConnectionClass <GameServerWebGLCustomNetworkConnection>(); webGLServer.useWebSockets = true; webGLServer.RegisterHandler(MsgType.Connect, OnWebGLConnected); webGLServer.RegisterHandler(MsgType.Disconnect, OnWebGLDisconnected); webGLServer.Listen(gameServerIp, gameServerPort); webGLHostId = webGLServer.serverHostId; NetworkServer.Listen(gameServerIp, gameServerPort); NetworkServer.RegisterHandler(GameServerNetworkProtocol.RequestGameServerRegistration, OnGameServerRegistrationRequested); } if (closeWhenEmpty) { StartCoroutine(CloseWhenEmptyService()); } }
public void Initialize() { webGLServer = new NetworkServerSimple(); webGLServer.SetNetworkConnectionClass <WebGLCustomNetworkConnection>(); webGLServer.useWebSockets = true; webGLServer.RegisterHandler(MsgType.Connect, this.OnWebGLConnected); webGLServer.RegisterHandler(MsgType.Disconnect, this.OnWebGLDisconnected); webGLServer.Listen(7777); hostId = webGLServer.serverHostId; _active = true; }
/// <summary> /// Unity's Start method. /// </summary> protected override void Start() { base.Start(); webGLServer.SetNetworkConnectionClass <MasterServerWebGLCustomNetworkConnection>(); webGLServer.useWebSockets = true; webGLServer.RegisterHandler(MsgType.Connect, OnWebGLConnected); webGLServer.RegisterHandler(MsgType.Disconnect, OnWebGLDisconnected); webGLServer.Listen(ip, port); webGLHostId = webGLServer.serverHostId; var config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, maxPlayers > 0 ? maxPlayers : 1024); NetworkServer.useWebSockets = false; NetworkServer.Listen(ip, port); }