The code that I am using right now is :
<!--Socket.io -->
<script src='http://172.16.17.185:3000/socket.io/socket.io.js'></script>
Where, 172.16.17.185 is the IP address on our LAN on which my server runs and port 3000 is used for socket.io communication.
The examples on the socket.io website use localhost in place of the server IP address. I started with this. Using localhost, my page loaded fine on the server, but no other PC on the LAN was able to create the socket object (as it was trying to look for socket.io on its localhost, which wasnt there).
So, I changed localhost to the IP address of the server, and everything worked fine.
Until, I tried accessing it from outside. Since this IP address is valid only on the LAN, it doesnt work like it should on the internet.
Is there a workaround for this problem ? or do I need to find the public IP of the server and use it ? Does this create any security vulnerabilities for the server as I dont have authorization ?
So far: http://www.ipsacademy.org/weather
Server code in web-server.js
If you want to access the socket.io server from outside you LAN, you must use public IP (and possibly avoid the use of port 3000).
In a production environment you must use a fronted proxy (like nginx) to translate requests to your socket.io server to the private LAN address.
Following example in the nginx blog you can use something like this:
location /socket.io/ {
proxy_pass http://172.16.17.185:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
This will not cause any security problem different from any publicly accessible service on Internet.
Looking at your code you are using separate http instances for serving page and socket.io. If you change that to use the same http server you can use relative URL for socket.io connection.