Create a game client/server in webgl
Hello,
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.
Answer by mwnDK1402 · Jun 19, 2016 at 08:24 PM
"The Transport Layer can use two protocols: UDP for generic communications, and WebSockets for WebGL."
Answer by sandvitch · Jun 20, 2016 at 03:25 AM
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();
NetworkTransport.Init(gConfig);
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
Your answer
Follow this Question
Related Questions
[uNET] Instantiated gameobjects not syncing for new clients 1 Answer
[Unet] set number for each player with ClientRpc 1 Answer
Unity 5.1 networking 0 Answers
Web multiplayer on my own server? 1 Answer
Unity UNET - Client unable to move 0 Answers