- Home /
WebGL sockets fails: Attempt to send to not connected connection
I build (unity 2017.1 stable) some client - server connection based on tutorial: https://www.youtube.com/watch?v=qGkkaNkq8co&t=3686s&ab_channel=N3KEN
So I have own code for server and client. Last problem that I have is fail to connect using WebGL. I put server in headless mode on linux (ubuntu) VPS and editor / standalone client builds works good.
But webgl builds not....(put build at hosting & vps and both fail on Chrome, Firefox and Opera)
As manual says (https://docs.unity3d.com/Manual/UNetUsingTransport.html) I should also add:
NetworkTransport.AddWebsocketHost(topology, 8887, null);
to server and that is done... Both Client and server receive Connect event, but when try send sth from server I got in logs: Attempt to send to not connected connection
Any idea what I'm missing?
Thanks
EDIT - ANSWER
I found answer... it's complex: 1. On client now using (as documentation says: server using different port for web socket & normal socket - and I want my server working with both in same time):
#if UNITY_WEBGL
private int m_port = 3002;
#else
private int m_port = 3001;
#endif
On server (and here was the biggest mistake). Also I must change port on another from normal socket, but:
m_hostId = NetworkTransport.AddHost(topo, m_port, null); m_webSocketId = NetworkTransport.AddWebsocketHost(topo, 3002, null);
And I use for each response m_hostId!!!!!!!!! So now, wen request come in, I take connectionId and hostId on which it comes and answer on that connection and host ID.
For now, I think that everything works fine. There is so many small thing that matters, so be carefull.......
Thanks anyway!
I liked your explanation... for client and for server.. in my case i have only changed server but was getting exception Firefox cannot establish connection. Which is 100% correct. $$anonymous$$y WebGL client was calling wrong port :( (7777) . but with Simple Web-socket Client - Chrome Web Store , i just tried ws port 6001, then connection opens. So, i think, it will work now.
Your answer
Follow this Question
Related Questions
WebSocket and WebGL error 1 Answer
Chat system is not working 1 Answer
Socket networking performance tips sought 0 Answers
LLAPI vs. pure C#.NET sockets 3 Answers
Best way to Instantiate and synchronize 300 000+ GameObjects over LAN? 2 Answers