Hi
Goal: Connect via LLAPI to server with WebGL
Problem: The following code works for standalone build and in editor. It also works for WebGL ONLY when run in the editor. This breaks when WebGL is built and run.
Unity Headless Linux Server code running in Editor
private void Start()
{
GlobalConfig config = new GlobalConfig();
NetworkTransport.Init(config);
//Host Topology
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
HostTopology topo = new HostTopology(cc, MAX_CONNECTIONS);
//Adding hosts
hostId = NetworkTransport.AddHost(topo, SERVER_PORT, null);
webHostId = NetworkTransport.AddWebsocketHost(topo, SERVER_WEB_PORT, null);
isStarted = true;
Debug.Log("---Server Started---");
game = new Game();
}
Client Connection Code
public void Connect()
{
GlobalConfig config = new GlobalConfig();
NetworkTransport.Init(config);
//Host Topology
ConnectionConfig cc = new ConnectionConfig();
reliableChannel = cc.AddChannel(QosType.Reliable);
unreliableChannel = cc.AddChannel(QosType.Unreliable);
HostTopology topo = new HostTopology(cc, MAX_CONNECTION);
#if UNITY_WEBGL
hostId = NetworkTransport.AddWebsocketHost(topo, 0); //Breaks here in WebGL build
connectionId = NetworkTransport.Connect(hostId, IP_ADDRESS, SERVER_WEB_PORT, 0, out error);
#else
hostId = NetworkTransport.AddHost(topo, 0);
connectionId = NetworkTransport.Connect(hostId, IP_ADDRESS, SERVER_PORT, 0, out error);
#endif
connectionTime = Time.time;
isConnected = true;
}
Thank you