Create a game client/server in webgl


I would like ot know if it’s possible to create a unity webgl multiplayer peer-to-peer game using websockets.

The game should allow players to create game (so beeing a server from the webgl game instance) and other players to join him with his ip address.

I would like to know if it’s possible to do that and which libs can do that.

Thanks for your help.

“The Transport Layer can use two protocols: UDP for generic communications, and WebSockets for WebGL.”

Thanks for your answer.

This is exaclty the lib I used but when a tried to host a game (so create a websocket to listen on it) I get an error, this is my code :

public int bufferSize = 1024;
public int port = 8008;
byte[] recBuffer;
MemoryStream stream;
ConnectionConfig config;
HostTopology topology;
int myReiliableChannelId;
int myUnreliableChannelId;
int hostID;
byte errorConnect;

recBuffer = new byte[bufferSize];
stream = new MemoryStream(recBuffer);
GlobalConfig gConfig = new GlobalConfig();
config = new ConnectionConfig();
myReiliableChannelId = config.AddChannel(QosType.Reliable);
myUnreliableChannelId = config.AddChannel(QosType.Unreliable);
topology = new HostTopology(config, 2);
hostID = NetworkTransport.AddWebsocketHost(topology, port, null);
if (hostID == -1)
       throw new Exception("Network initialization failed");

And then, hostID = -1 and it throw the exception,

Did I miss something ?

Thanks for your help