Azure Web PubSub transport is designed to use Azure's managed realtime service to transfer data between unity server and clients.
Azure's managed Web PubSub service support Websocket
, so if you are seeking solution for Websocket
or extend your game to support WebGL
platform, this transport is just for you.
This transport hides most of the technical details, all you need to do is to create an Azure Web PubSub service, and connect your service with a connection string.
What's more, with managed Azure Web PubSub service, you can have scalability, high availability, live monitoring, private link, auto-reconnect functionality and more.
docker run -p 8080:80 albertxavier100/azure-web-pubsub-transport-sample-unity-netcode-bootstrap:0.2.0 -e Hub="unity_hub_docker" ConnectionString="<azure-web-pubsub-connection-string>"
Azure provides free SKU to create Web PubSub. Feel free to create one.
- Quickstart: Create a Web PubSub instance from Azure portal
- Quickstart: Create a Web PubSub instance with Azure CLI
Optional:
- Install ParrelSync: ParrelSync is a Unity editor extension that allows users to test multiplayer gameplay without building the project by having another Unity editor window opened and mirror the changes from the original project.
- Copy connection string in
Keys
page of your Web PubSub service you just created. - Install dotnet runtime if you don't have one.
- In
Proejct
view, right clickPackages/Azure Web PubSub Transport for Netcode for Gameobjects
, and clickShow in Explorer
. - Extact
Resources/NegotiateServersSource~.zip
and go into the extracted folderNegotiateServersSource~/AWPSNegotiateServer
, renameappseetings.sample.json
toappsettings.json
, fill the connection string inConnectionString
section. - In terminal app, run
dotnet run
to start negotiation server. - Get listening URL in console log. For example:
Now listening on: https://localhost:7172
- Download latest
azure-webpubsub-transport.unitypackage
package from[Releases](https://github.com/albertxavier100/azure-web-pubsub-transport/releases)
. - Import
azure-webpubsub-transport.unitypackage
to your Unity project. - Add
AzureWebPubSubTransport
component to your GameObject containing your NetworkManager. - Set the
Network Transport
field on the NetworkManager to theAzureWebPubSubTransport
. - Enter a room name into the
Room Name
field of theAzureWebPubSubTransport
. - Enter negotiate endpoint. For example,
https://localhost:7172/negotiate
if you use the builtin developing negotiate server. - Use the
StartServer
,StartHost
andStartClient
functions as usually to host a game and have clients connect to it.
At this point, you should be able to exchanges data between unity server and client.
So far, the transport should be able to use.
The below sections is
optional
to read for explaining who to use Azure Web PubSub service to exhcange data between your server and clients. The folliowing contains details about how Unity and Azure Web PubSub service are connected. The following is useful to read when you scalability is in your plan.
This transport supports concept room
, which allows a server and multiple clients to enter.
All clients in the same room will synchronize through a server, so that they can paly together.
Take Alice's room for an example.
Logically, the server and one client's connection is bidirectional communication. In order to do so, Azure Web PubSub service handles:
- Connection Negotiation: Servers and clients enter some room.
- Data Synchronization: Synchronize network data among server and clients.
In generaral, negotiate webapp is used to redirect client/server connection to Azure Web PubSub service. The negotiate webapp can also be the same web app to your server. If you consider scalibility, consider keeping standalone negotiate web apps to handle Websockets connection request.
- Server requests redirect information from negotiate web app with the room name (Alice's Room).
- Server established Websocket connection Azure Web PubSub service only when negotiate web app ensure there's no server subscribes to the room channel.
- Client requests redirect information from negotiate web app with the room name ((Alice's Room)).
- Client establishes Websocket connection to Azure Web PubSub service only when negotiate web app ensures there's a server subscribes to the room channel.
- Notify server via the room channel, that this client is connected.