I currently have a WebSocket server (C#) and a client (JavaScript / HTML5). This works great on my local network, however when I listen to and make the client connect to my ‘real’ IP (which is the IP of my router identifiable worldwide, i.e. instead of 192.168.x.x), it doesn’t work. The WebSocket class does get a readyState of 1, but when I send anything from the client to the server (or the other way round), the message doesn’t arrive.
I already set my router to enable port forwarding, otherwise it wouldn’t work anyway (I tried not enabling this and the WebSocket immediately got a readyState of 2).
JavaScript code:
var ws = new WebSocket("ws://some.real.ip.address:myport");
// For privacy reasons I'd like to keep the address and port private
C# code (I’m using the Nugget library to implement a socket server):
var nugget = new WebSocketServer(myport, "*", "ws://some.real.ip.address:myport");
Obviously, the address and port are the same.
What could be the cause of it? Is it possible that my ISP doesn’t allow socket connections when my computer is the server? If so, how come the WebSocket does get a readyState of 1?
Thanks a lot.
It was my fault – not sure if this answer will help anybody, but I’m listening to
/bkespecifically, and I did not pass this in the JavaScriptWebSocketconstructor…