This document is about: FUSION 2
SWITCH TO

Client Server Connection Process

The connection process between Fusion Clients and Servers involves multiple stages to establish a reliable peer-to-peer communication, often traversing NAT (Network Address Translation) environments using the Photon Cloud and STUN Services. The main goal is to establish direct connection between peers in a gaming session, ensuring low latency and high performance.

General Process Overview

  1. Session Initiation, Creation, and Joining:
  • The Server peer creates a new session using the Photon Cloud.
  • The client requests to join a session via the Photon Cloud.
  1. Peer Discovery and Reflexive Address Exchange:
  • Using the STUN (Session Traversal Utilities for NAT) protocol, both the client and server request reflexive addresses (external, public IPs and ports) from an external STUN Server. This allows each peer to identify their public-facing address, which is essential for connecting through NATs.
  • The reflexive information is then shared between peers, enabling direct communication in most cases.
  1. Connection Establishment:
  • The client attempts to connect to the server using the reflexive information. If direct peer-to-peer (P2P) connection fails, the connection can be relayed through the Photon Cloud.
  • The server listens for connection requests, either via direct sockets (UDP) or through a relay via the Photon Cloud.
  • Upon a successful connection, both the client and server begin exchanging game updates.
  1. Handling Connection Failures:
  • If connection attempts exceed a certain threshold, the client shuts down its network operations and stops trying to connect.
  • The server continues listening for further connection attempts, either directly or via relay services, until the client successfully connects or aborts the process.

This process ensures that clients and servers can reliably connect and communicate, regardless of the network environment, using a combination of direct connections and relay services if necessary.

Core Components

  • STUN Service: Provides reflexive information to peers, allowing them to establish direct communication through NAT environments.
  • Photon Cloud: Manages the creation of sessions, relays connection attempts when necessary, and facilitates peer discovery.

Session Creation and Joining

The following diagram illustrates the general flow of the session creation and further setup:

Fusion Server Start and Session Creation Process
Fusion Server Start and Session Creation Process
  1. 1. The server starts the game in Server mode.
  2. 2. The server creates a new session using the Photon Cloud.
  3. 3. The Photon Cloud acknowledges the session creation.
  4. 4. The server sends a Join Request Protocol Message to the Photon Cloud. This is used to set up the session with custom properties related to the ClientServer Mode in Fusion.
  5. 5. The Photon Cloud acknowledges the Join Request.
  6. 6. The Photon Cloud requests the server to start.
  7. 7. The server starts and initializes the NetworkRunner.
  8. 8. The server executes the procedure to get the local network address.
  9. 9. The server sends a STUN Request to a STUN Server.
  10. 10. The server receives the reflexive address from the STUN Server.
  11. 11. The server sends the reflexive address to the Photon Cloud.

The diagram below illustrates the client joining process:

Fusion Client Start and Join Process
Fusion Client Start and Join Process
  1. 1. The client starts the game in Client mode.
  2. 2. The client attempts to join a random session using the Photon Cloud.
  3. 3. The Photon Cloud confirms the session joining.
  4. 4. The client sends a Join Request Protocol Message to the Photon Cloud. This is used to register the client in the session.
  5. 5. The Photon Cloud acknowledges the Join Request.
  6. 6. The Photon Cloud requests the client to start.
  7. 7. The client starts and initializes the NetworkRunner.
  8. 8. The client executes the procedure to get the local network address.
  9. 9. The client sends a STUN Request to a STUN Server.
  10. 10. The client receives the reflexive address from the STUN Server.
  11. 11. The client sends the reflexive address to the Photon Cloud.

Connection Process Flow

The following diagram illustrates the general flow of the connection process between Fusion Clients and Servers. All the steps described below are executed for each client-server connection attempt.

Fusion Connection Process
Fusion Connection Process

Here is the step-by-step process:

  1. 1. Photon Cloud sends the reflexive address of the server to the client.
  2. 2. Photon Cloud sends the reflexive address of the client to the server.

In parallel, the client and server will perform the steps below:

(Client side) at every Connection Attempt Interval:

  1. 3. The client attempts to connect to the server using the public reflexive address, if the attempt is less than 2/3 of the Connection Attempts Limit.
  2. 4. Otherwise, it sends a connection request to the Photon Cloud.
  3. 5. The Photon Cloud relays the connection request to the server.
  4. 6. If the Connection Attempts Limit is reached, the client stops trying to connect and shuts down its network operations.

The connection attempts interval is fixed at 500ms, and the connection attempts limit is set to 10.

(Server side) it listens for connection requests and performs the following steps:

  1. The server sends UDP ping packets to the client's reflexive address. This is used to update the server's local network router table with the client's reflexive address, which in some cases is necessary to establish a direct connection, as the router may block incoming packets from unknown sources.

There are two possible outcomes at this point:

(a) The client can communicate directly with the server:

  1. 8. The server accepts the connection request from the client via the default socket, meaning a direct connection has been established.
  2. 9. The client then starts to send game updates to the server.

(b) Or the connection can be relayed through the Photon Cloud:

  1. 10. The server accepts the connection request from the client via the Photon Cloud relay.
  2. 11. The Photon Cloud then relays the connection confirmation to the client.
  3. 12. The client then starts to send game updates to the server via the Photon Cloud relay.
  4. 13. The server receives the game updates from the client via the Photon Cloud relay.

Once the connection is established, the client and server can communicate directly or through the Photon Cloud relay, depending on the network environment and the success of the direct connection attempts.

Conclusion

The connection process between Fusion clients and servers is a multi-stage process that involves several mechanisms to establish reliable peer-to-peer communication. By leveraging the Photon Cloud and STUN services, Fusion can ensure that clients and servers can connect and communicate effectively, even in complex network environments with NAT traversal requirements.

Back to top