PUN Classic (v1), PUN 2 and Bolt are in maintenance mode. PUN 2 will support Unity 2019 to 2022, but no new features will be added. Of course all your PUN & Bolt projects will continue to work and run with the known performance in the future. For any upcoming or new projects: please switch to Photon Fusion or Quantum.

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.

Setup Accept Mode
Setup Accept Mode.

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 or BoltMatchmaking.JoinSession to send a request to the Server, trying to connect to it:

C#

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:

C#

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:

C#

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 ConnectionRequest and Connected on the server.

If your Accept Mode is Manual, you must either call:

C#

public static void BoltNetwork.Accept(UdpEndPoint endpoint);
public static void BoltNetwork.Accept(UdpEndPoint endpoint, IProtocolToken acceptToken);

or

C#

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:

C#

public virtual void GlobalEventListenerBase.Connected(BoltConnection connection);

Or this one, if the connection was refused:

C#

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:

Accept-Refuse Flow
Accept-Refuse Flow.
Back to top