Accepting and Refusing Connections
Bolt allows you to accept or refuse an incoming connection attempt early, before a full connection has been made and before the client even starts loading the scene. Normally all connections are accepted automatically, unless you go into Bolt Settings and change Accept Mode to manual (see the figure below). An example use case would be to refuse incoming connections because the server is full.
Clients can send tokens to the server when connecting (e.g. for entering a password protected game session, third party session tickets, etc). This token is passed to ConnectionRequest (see below) and further along in the handshake available as a member of BoltConnection (ConnectToken) available from callbacks like Connected.
On the Client you can use one of the versions of BoltNetwork.Connect to send a request to the Server, trying to connect to it:
public static void BoltNetwork.Connect(UdpSession session, IProtocolToken token); public static void BoltNetwork.Connect(UdpSession session); public static void BoltNetwork.Connect(UdpEndPoint endpoint, IProtocolToken token); public static void BoltNetwork.Connect(UdpEndPoint endpoint);
After you call the Connect method, the following callback will signal that this peer is attempting to connect to the server:
public virtual void GlobalEventListenerBase.ConnectAttempt(UdpEndPoint endpoint, IProtocolToken token);
On the Server, you will receive the following request when a new player tries to connect:
public virtual void GlobalEventListenerBase.ConnectRequest(UdpEndPoint endpoint, IProtocolToken token);
Clients can pass tokens when they connect to the server. This token is used for both ConnectionRequest and Connected on the server.
If your Accept Mode is manual, you must either call:
public static void BoltNetwork.Accept(UdpEndPoint endpoint); public static void BoltNetwork.Accept(UdpEndPoint endpoint, IProtocolToken acceptToken);
public static void BoltNetwork.Refuse(UdpEndPoint endpoint); public static void BoltNetwork.Refuse(UdpEndPoint endpoint, IProtocolToken refuseToken);
These methods allow you to return a token if you wish - use this for a response for the client, such as an error message result that you can convert into text for displaying to the user.
The client will receive the following callback if their connection was accepted:
public virtual void GlobalEventListenerBase.Connected(BoltConnection connection);
Or this one, if the connection was refused:
public virtual void GlobalEventListenerBase.ConnectRefused(UdpEndPoint endpoint, IProtocolToken token);
The client can retrieve the Accept token with BoltConnection.AcceptToken inside the Connected callback. The sequence diagram below summarises the overall process: