-->
Page 1 of 3

How to connect to websocket server using public/local ip

PostPosted: Fri Apr 29, 2016 7:25 am
by Focak
Hi ,

I made websocket server on my local network.
So if I use local IP address for websocket, then I can connect to server from my local network but I can not connect from public network.

ESP8266WebServer server(80);
WebSocketsServer webSocket = WebSocketsServer(81);

var wsUri = "ws://192.168.1.129:81/";

and if I use dns host for websocket then I can connect to server from public network but I cannot connect from local network

ESP8266WebServer server(80);
WebSocketsServer webSocket = WebSocketsServer(81);

var wsUri = "ws://dns-host:81/";

is there any way to make websocket server which I can connect same time from local network also from public network ?

Re: How to connect to websocket server using public/local i

PostPosted: Fri Apr 29, 2016 7:55 am
by martinayotte
You need to add a "port forwarding" rule in your exposed router, otherwise port 81 is not accessible to outside world.

Re: How to connect to websocket server using public/local i

PostPosted: Fri Apr 29, 2016 8:09 am
by Focak
Yes I forwarded ports 80 and 81 to my local IP. In both scenarios I can open webserver page from both local and public ip.
But websocket can not connect if I use dns host in script for websocket:

var wsUri = "ws://dns-host:81/";

router does not have nat loopback so when I try to connect from local
network browser load script with var wsUri = "ws://dns-host:81/";
but webcosket cannot connect .

Re: How to connect to websocket server using public/local i

PostPosted: Fri Apr 29, 2016 9:43 am
by martinayotte
Did you tried it while been really outside from your local network ?
(I have this kind of issue with my ISP modem, where routing is refused when done from inside my local network)
Did you tried with your external IP instead of "dns-host" ? (could be a local DNS issue)