# Networking Models

## Client-Server architecture

The **client-server model** is the most widely used approach in multiplayer networking. In this model:

* **Server**: The authoritative instance of the game. It manages game logic, synchronizes game state, validates player actions, and handles communication between clients.
* **Client**: A player's instance of the game. It sends input to the server and receives updates about the game state.

There are two main types of servers:

### **Dedicated server**

The server runs as its own process, separate from any player. It’s more secure and scalable, commonly used in competitive or large-scale games.

<figure><img src="https://1328095063-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MheH2hMo3djr9VSyxTE%2Fuploads%2Fgit-blob-ec94c5b6d93779020ea41f75dbb083b9266a47ae%2Fclient-server-model.svg?alt=media" alt="An image showing multiple clients connected to a single server" width="563"><figcaption><p>A dedicated server model</p></figcaption></figure>

As you can see from the above diagram, the clients (players) are all connected directly to the server and communicate with it instead of with each other.

***

### **Host (listen-server)**

The server and one of the clients run in the same process. This is common in smaller games or development environments.

<figure><img src="https://1328095063-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MheH2hMo3djr9VSyxTE%2Fuploads%2Fgit-blob-1f8967fc393f3b673d2c616dfcffd7972b3c09d7%2Flisten-server-model.svg?alt=media" alt="An image showing multiple clients connected to a single server which is also acting as a client itself" width="563"><figcaption><p>A listen-server model</p></figcaption></figure>

The above diagram demonstrates how the listen-server is similar to the dedicated server model where all clients connect directly with the server, but unlike the dedicated server, the listen server is also acting as a client (player).

{% hint style="success" %}
FishNet supports both dedicated and listen-server models out of the box.
{% endhint %}

***

## Peer-to-peer (P2P)

In **peer-to-peer networking**, each player (or peer) connects directly to others without a central server. This reduces latency and server costs but comes with challenges:

* Poor security and cheating prevention
* Difficult to synchronize game state reliably
* NAT traversal issues

<figure><img src="https://1328095063-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MheH2hMo3djr9VSyxTE%2Fuploads%2Fgit-blob-71c52be573c6467003e15649ea1ab82eb63648d0%2Fp2p-model.svg?alt=media" alt="An image of four clients all interconnected with each other." width="563"><figcaption><p>A peer-to-peer model</p></figcaption></figure>

P2P is rarely used in modern real-time multiplayer games, especially competitive ones, due to these drawbacks. FishNet does not use P2P, as it is designed around the client-server model for reliability and security.

{% hint style="info" %}
Very often a listen server setup is referred to as P2P, FishNet does support a listen server.
{% endhint %}

***

## Relay servers

Sometimes clients are unable to connect directly to the server due to **NAT (Network Address Translation)** or **firewall** restrictions. A **relay server** acts as a middleman to forward traffic between clients and the server.

<figure><img src="https://1328095063-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MheH2hMo3djr9VSyxTE%2Fuploads%2Fgit-blob-63e35fd00d7166f8822fa910ecdf191eb985788c%2Frelay-server-model.svg?alt=media" alt="An image of a three clients connecting to a server which links them to a server and client instance." width="563"><figcaption><p>A relay server</p></figcaption></figure>

Relay servers:

* Allow connectivity when direct connections fail
* Introduce additional latency
* May be used as a fallback or for web-based games

{% hint style="success" %}
Fish-Networking supports multiple third-party relay services including [Unity's Relay](https://unity.com/products/relay), [Edgegap's Distributed Relay](https://edgegap.com/platform/distributed-relay), [Photon Realtime](https://www.photonengine.com/Realtime), [Epic Online Services' Relay Service](https://dev.epicgames.com/docs/epic-online-services/eos-overview#peer-to-peer-p2p-connections), and [Steam Datagram Relay](https://partner.steamgames.com/doc/features/multiplayer/steamdatagramrelay).
{% endhint %}

***

### Host migration

When using a listen server, the host leaving the game would cause all players to leave the game; **Host migration** is a feature for maintaining game sessions in the event the current host disconnects or experiences network issues. It enables a new host to be elected from the remaining connected players, minimizing disruption and ensuring the game session can continue seamlessly.

{% hint style="warning" %}
Fish-Networking doesn't yet have built-in host migration, but it is a feature that may be added in the future.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fish-networking.gitbook.io/docs/guides/high-level-overview/networking-models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
