Accepting and Refusing Connections
Photon 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
ConnectToken) available from callbacks like
On the Client, you can use one of the versions of
BoltMatchmaking.JoinSession to send a request to the Server, trying to connect to it:
public static void BoltMatchmaking.JoinSession(string sessionID, IProtocolToken token); public static void BoltMatchmaking.JoinSession(UdpSession session, IProtocolToken token); public static void BoltMatchmaking.JoinRandomSession(IProtocolToken token); public static void BoltMatchmaking.JoinRandomSession(UdpSessionFilter sessionFilter, IProtocolToken token); public static void BoltNetwork.Connect(UdpEndPoint endpoint, IProtocolToken token); public static void BoltNetwork.Connect(UdpEndPoint endpoint);
After you call one of those methods, 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 try to connect to the server.
This Token is used for both
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
The sequence diagram below summarises the overall process: