5

Ciao, I'm implementing a webRTC many-to-many videoconferencing system, actually, I already did it, I am using socket.IO as signalling server, and everything goes super well, I am using EnterpriseDB Apache for serving my .html file on port (8081) and Node.js for serving socket.IO on port (3000), It is working like charm in localhost, no errors, My ISSUE is serving for external access with my public IP, I am testing with my friends and these browsing services: www.browserstack.com and www.browserling.com (trial versions).

  • with www.browserstack.com, everything is working fine with either mozilla 42 or chrome 47

  • with www.browserling.com, I got these errors

    Firefox 41: ReferenceError: io is not defined

    Chrome 45: Failed to load resource http://localhost:3000/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED Uncaught ReferenceError: io is not defined

  • with my friends, I am having the same issues as www.browserling.com, but they are using the latest browser versions (Chrome 47 and Firefox 42) for connecting to my PC server.

I think this is not a browser version issue, The issue is on serving the socket.io.js file, finally, here is my code:

It shows just the important things in order to solve this problem:

///NODE.JS DIRECTORY
////////////////////serverside.js
var port = 3000;
var io = require('socket.io').listen(port);
io.sockets.on('connection', function (socket){.........}


///APACHE DIRECTORY
////////////////////clientside.js 
//Connect to signalling server   
var socket = io.connect("http://localhost:3000");

////////////////////avq.html
<!DOCTYPE html>

<html lang="es">

    <head><meta charset="UTF-8">
    </head> 
    <body>
        <script src="http://localhost:3000/socket.io/socket.io.js"></script>
        <script src="js/clientside.js"></script>
    </body>
</html>

this is my server URL if anyone wants to try: http://201.209.104.33:8081/webrtcexamples/avq.html

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171

2 Answers2

9

localhost is a special host name that points to the same computer as the one requesting it. So anyone using a different computer than yours and trying to connect to localhost will try to connect to its own computer, not yours. As the server is not running on their computer, they quite obviously get a "connection refused" error.

You need to replace localhost with a globally accessible address (domain name or IP address). This also implies that you need to have your router map your external IP address to your computer running the server for this port (otherwise they will connect to your router, not your server).

jcaron
  • 17,302
  • 6
  • 32
  • 46
  • No, I think that's not the issue, i have seen a lot a code on the web and many people do this with this file socket.io.js, and I cant use my dynamic public ip for connecting to my own machine, If i do this http://201.209.104.33:3000/socket.io/socket.io.js wouldnt work in my own machine – Jose Ricardo Citerio Alcala Dec 13 '15 at 00:37
  • 3
    @user4216713, I'm telling you it's definitely the issue. `localhost` is definitely always a reference to the current local computer, as seen by whoever is using that address. Nobody can connect to your computer using `localhost`. – jcaron Dec 13 '15 at 00:41
  • As stated previously, you also need to configure your router so that connections to port 3000 are forwarded to your computer. – jcaron Dec 13 '15 at 00:41
  • As for dynamic IP addresses, you'll need to use a dynamic DNS service which will remap to your current local IP address. – jcaron Dec 13 '15 at 00:43
  • Why does it work on www.browserstack.com?, I dont understand – Jose Ricardo Citerio Alcala Dec 13 '15 at 00:44
  • I have no idea what you tested and how, but most definitely, if you're telling a remote browser to connect to localhost, it is not connected to your computer. – jcaron Dec 13 '15 at 00:47
  • @user4216713 If your code was server-side, localhost would refer to the server. However, any client-side code, such as js in the browser, localhost will not refer to the server, but your own computer. As stated, localhost will always refer to the computer calling the code. – Daedalus Dec 13 '15 at 00:49
  • yes, you are right men, maybe this service www.browserstack.com has casually a node.js socket.io service running on port 3000, thank you, I'll make the changes. – Jose Ricardo Citerio Alcala Dec 13 '15 at 01:03
  • Really man, you are f*cking awesome, that was the problem, I just enabled the port 3000 on my router and voila. – Jose Ricardo Citerio Alcala Dec 13 '15 at 01:40
3

try io.connect("http://201.209.104.33:3000"); instead of io.connect("http://localhost:3000");

EDIT

You need to run the socket on the server that it is being used. So if you run it on your PC, your friends pc will not see it, because when it connects to localhost, it will try to connect to the localhost of THEIR pc. Not yours.

I had the same issue before. You need to run it off of the server so that everyone can connect to it.

Haring10
  • 1,517
  • 1
  • 19
  • 37