Fishnet WebGL
This guide will help you use FishNet's Websocket Transport, Bayou, and create a headless server on Edgegap for a Unity project.
You can find the final sample project on GitHub, under the Fishnet_v4.1.6R_WebGL_Matchmaker folder. This guide should work with any version of Fishnet, so long as you use the appropriate version of Bayou for it.
The Start Game button in the sample has two modes, selected on the MatchmakingSystem gameObject in the MainMenu scene:
Direct connection (default) - the client connects to a server address and port you set. Test against a local server first, then against a deployment you start from the Edgegap dashboard. No matchmaker is needed.
Edgegap Matchmaker (optional, disabled by default) - the Edgegap Matchmaker groups players, Edgegap starts a dedicated server near them, and every client connects to it automatically.
Unity requirements
This project is tested on Unity version 2021.3.45f2, with FishNet 4.1.6R, the Bayou transport and the Edgegap Unity SDK. You will need the following modules to be installed with it:
WebGL Build Support;
Linux Dedicated Server Build Support;
Linux Build Support (Mono).
You will also need Docker to containerize the server.
Switch the transport
The sample already uses Bayou on port 7770. To do the same in your own project, download the Bayou Unity package from its GitHub releases. Import the package in the game project with the toolbar under Asset/Import Package/Custom Package....
Open the MainMenu scene located under Assets/SpaceEdge/Scenes. In the NetworkManager gameObject, remove the Tugboat transport component. Replace it with the Bayou transport, located under Assets/FishNet/Plugins/Bayou. Take note of the port value that's set, in this case 7770.
You don't need FishNet's Start On Headless option, and the sample leaves it off. In server builds, the EdgegapServerLifecycle component (under Assets/Edgegap) starts the FishNet server on 0.0.0.0:7770, so the same scene works for client and server builds. On Edgegap, it also stops the deployment when nobody joins within 120 seconds, or 30 seconds after the last player leaves.
Build the game server & Containerizing
Build the server with the Tools/Edgegap/Build Linux Dedicated Server toolbar menu. The output goes to Builds/EdgegapServer/, which the sample's Dockerfile copies into the image.
To test it locally, run it in Docker:
The log shows Edgegap Server | Starting server on 0.0.0.0:7770. and Not running on Edgegap, self-stop disabled.
Testing the client
In the editor or locally
Make a WebGL client build (see On Itch.io for the build settings), or build it from the command line:
Serve Builds/Client/webgl (for example with python -m http.server 8080), open http://localhost:8080 in two tabs, then click on Start Game. The MatchmakingSystem defaults (Direct Address set to localhost, Direct Port set to 7770, Direct Use Wss off) connect to the local server. Desktop builds (-edgegapClientTarget win64) work too, since Bayou supports native clients.
On an Edgegap server
Push the image to your Container Registry. Your registry project, username and token are on the dashboard's Container Registry page.
Then build and push the image:
In the Edgegap dashboard, create an application and a version for that image:
Port: name
gameport, port7770, protocolWS, withTLS Upgradeenabled. Edgegap terminates TLS, so browsers connect withwss://while the server speaks plainws(see Websockets (WS) and Secure Websockets (WSS)).Container registry username and token: set them, otherwise deployments fail to pull the image.
Deploy the version from the dashboard. On the MatchmakingSystem gameObject, set Direct Address to the deployment's host (<id>.pr.edgegap.net), Direct Port to its external port, and enable Direct Use Wss. Rebuild the client and click on Start Game.
With the Edgegap Matchmaker (optional)
Turn on the matchmaker once direct connection works:
In the sample's
matchmaker-config.json, setapplication.nameandversionto your application and version, and list every origin that serves the WebGL build inallowed_cors_origins.In the dashboard, open Matchmaker, click
Create Matchmaker, upload the file, then clickCreate and Start.In the
MainMenuscene, copy the matchmaker'sAPI URLandAuth Tokeninto theBase UrlandAuth Tokenfields of theEdgegap Matchmaking Clientcomponent on theEdgegapgameObject. Then enableUse Edgegap Matchmakeron theMatchmakingSystemgameObject.Rebuild the client, serve it from an origin listed in
allowed_cors_origins(for examplehttp://localhost:8080), open two tabs and click onStart Gamein both.
The client creates a ticket, waits for a server to be assigned, then connects with wss://. The casual profile matches 2 to 4 players. It also lowers the minimum to 1 player after 30 seconds, but a lone player may only get a server when the ticket nears its 5-minute expiration, so test with two clients.
To ship a new server build: build the server, push a new tag, create a new app version, then in the matchmaker click Stop, edit application.version and click Start (see Rolling Updates).
On Itch.io
Once you've confirmed the game client works locally, it should also work in Itch.io. To upload your game there, you will need to make a client build in the Build screen of the Unity Editor, under File -> Build Settings. Select the following options:
Set
PlatformtoWebGL;Open up the
Player Settings. UnderPlayer -> Publishing Settings, set theCompression FormattoGzipand make sure theDecompression Fallbackoption is selected. Save these settings, and close the window.

Then press build and select a new empty folder named build as the file destination. Compress the files of this build folder into a zip folder, making sure that they are at the root of it. Then upload the zip folder to your Itch project, and make sure to select the option for the file to play in the browser. The game should then work the same way as locally. In matchmaker mode, add your Itch.io page's origin to allowed_cors_origins first.
Last updated
Was this helpful?

