// Start is called before the first frame update void Start() { try { _server = UnityNetcode.CreateServer( _ip, // string public IP clients will connect to _port, // port clients will connect to protocolID, // ulong number used to identify this application. must be the same as the token server generating connect tokens. maxClients, // maximum number of clients who can connect privateKey); // byte[32] private encryption key shared between token server and game server // Called when a client connects to the server _server.ClientConnectedEvent.AddListener(ClientConnected); // void( RemoteClient client ); // Called when a client disconnects from the server _server.ClientDisconnectedEvent.AddListener(ClientDisconnected); // void( RemoteClient client ); // Called when a client sends a payload to the server // Note that byte[] payload will be returned to a pool after the callback, so don't keep a reference to it. _server.ClientMessageEvent.AddListener(ClientMessageEvent); // void( RemoteClient sender, ByteBuffer payload ); _server.StartServer(); // start listening for clients } catch (Exception e) { Application.Quit(); } }
private void Start() { server = UnityNetcode.CreateServer(PublicIP, Port, 0x1122334455667788L, MaxClients, privateKey); server.ClientConnectedEvent.AddListener(Server_OnClientConnected); server.ClientDisconnectedEvent.AddListener(Server_OnClientDisconnected); server.ClientMessageEvent.AddListener(Server_OnClientMessage); server.StartServer(); logLine("Server started"); }
private void Start() { RegisterPackets(); server = UnityNetcode.CreateServer(PublicIP, Port, ProtocolID, MaxClients, privateKey); server.internalServer.LogLevel = NetcodeLogLevel.Debug; server.ClientConnectedEvent.AddListener(Server_OnClientConnected); server.ClientDisconnectedEvent.AddListener(Server_OnClientDisconnected); server.ClientMessageEvent.AddListener(Server_OnClientMessage); server.internalServer.Tickrate = 60; server.StartServer(); logLine("Server started"); }