Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.io 1.0 error: ERR_NAME_NOT_RESOLVED

Tags:

socket.io

I have a node.js server using socket.io. The idea is to allow two different html files to communicate information to each other through this server. All was well with socket.io ver0.9.16 until ver 1.0 came out. Now, I receive a few errors on both the client and server side, the most apparent (to me, since I am new to this) is the ERR_NAME_NOT_RESOLVED error that I find when I start up the locally hosted server.js file and attempt to connect to it through the client html.

When I open the console in Google Chrome, I find this error which prints again to the console every second or so:

GET http://file/socket.io/?EIO=2&transport=polling&t=1406247171961-0 net::ERR_NAME_NOT_RESOLVED 

What follows are snippets of places where I may have problems in my html and server.js files as well as in a js file that is used by my html file to connect to the server.

index.html

I think this bit of code gets the socket.io client code from the localhost server. This is the first place where I may think that I have a problem

<script src="http://localhost:4000/socket.io/socket.io.js "></script> 

In addition, the following is where I import my index.js file which is used to connect to the server

<script type="text/javascript" src="scriptsTeacher.js" ></script>

-

server.js

This code (according to my sources) should set up a server on the localhost with port 4000 to which clients can connect and send/receive information

 var io;
 io = require('socket.io').listen(4000);
 io.on('connection', function(socket) 
 {   
    console.log("user connected");
 });

-

index.js

This code is used by the index.html which has it connect to a server listening on port 4000 using socket.io.

var socket = io.connect('localhost:4000');

-

Currently, there are two blatant errors that I can find. They are probably not the root of the problem, but they are as far as my limited debugging experience can take me.

  1. ERR_NAME_NOT_RESOLVED: (NOTE: I have looked at socket.io ERR_NAME_NOT_RESOLVED and it was not entirely useful since that user had a typo by using http:\\ instead of http://). As stated before, when opening index.html in Google Chrome and accessing the console, I receive multiple ERR_NAME_NOT_RESOLVED errors.

  2. There is no "Welcome to socket.io" message when accessing localhost:4000 I am certain that there should be such a message. Note that there is no 404 error, when I start up the server, I can access that webpage, but it is blank. If the server is not running, then I do get a "Webpage not found" message.

My question is this: Is there anything that I am not doing but should? As I said, I am new to this, and after some hunting around on the internet, I have a suspicion that there is some server (HTTP, Express, Express 3/4?) that I am not establishing. However, it is of note that the code worked as is in ver0.9.16 (using the .socket() and .listen() functions which were removed from my code for migration to ver1.0). If there is any information that is missing, I will do my best to provide it as soon as possible.

-

I am using:
Macintosh OS 10.6.8
Google Chrome version 36.0.1985.125
socket.io ver1.0
node.js v0.10.29

like image 240
D H Avatar asked Jul 25 '14 00:07

D H


3 Answers

The address in the error is wrong (assuming you haven't set up a local name resolver).

The address in the error begins with:

file

When it should begin with something like:

localhost:4000

The issue is probably in some of the js-config files for the web application (not the server). Or maybe you're trying to access the file locally (eg. just open the html-file in the browser) instead of typing the address localhost:4000.

like image 138
Felix Sandström Avatar answered Oct 24 '22 05:10

Felix Sandström


I had the same problem that running file in the browser: eg. "file:///C:/apppath/index.html" Try running from the server eg. "http://your.app:4000/index.html"

like image 27
Karman Valenzuela Avatar answered Oct 24 '22 06:10

Karman Valenzuela


I had the same issue - I wasn't able to connect to my socket.io server through my client on the same machine on mac. I disabled the firewall and it resolved the issue. I guess we could use xhr-polling instead and overcome this.

Vikram

like image 1
Vikram Avatar answered Oct 24 '22 05:10

Vikram