socket.io client 'emit' shows a weird error in chrome console

Problem

I am developing a simple application using the current latest versions of nodejs + socket.io on Windows. I have encountered a problem when the socket get created on the client side, but socket.emit results in the following output in the console (using Google Chrome):

GET http://0.0.34.184:8888/socket.io/1/?t=1321385855665&jsonp=0

Which is quite strange because I am testing on localhost:8888 so it should be at least 127.0.0.1 and not 0.0.34.184. The socket.io client on the page is requested from the server in the tag as follows:

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

Then I connect using the following code:

socket = io.connect('localhost:8888');
socket.on("my_event", receiveNetEvent);

console.log('LOG: sio init complete, socket=' + socket);

The log states that socket=[Object object] which is not null or undefined so everything should work.

The sending itseld is performed in the following function:

function sendRequest(request){
    socket.emit('request', request);
}

The request object, passed to the function is formed and passed like this:

var initRequest = {};
initRequest.subject = 'weather';
initRequest.key = 'initial';

sendRequest(initRequest);

And it is a valid json object according, again, to console.log().

All this leaves me totally clueless about any possible reason of the happening.

Problem courtesy of: noncom

Solution

Try adding http:// to the connect path. That solved this error for me.

socket = io.connect('http://localhost:8888');
Solution courtesy of: respectTheCode

Discussion

I faced the same issue but I had a different reason. My setup was running the socket client on a tomcat server with port 9000 and was connecting to localhost:80 running nodejs, what i didn't realize is the port was mandatory even if it was 80 by default.

SO i gave the port and replaced

io.connect('http://localhost') with io.connect('http://localhost:80')

Because both my servers were pointing to same domain which in this case localhost... socket io for some reason was taking port 9000

Hope it helps somebody.

Discussion courtesy of: Abhi

I was also facing the same problem but resolved it by forcing only xhr-polling to server side javascript and that worked out.

    var io = require('socket.io').listen(8000);
    io.configure(function () {
      io.set('transports', ['xhr-polling']);
    });
<..Rest code..>
Discussion courtesy of: Tejas

This recipe can be found in it's original form on Stack Over Flow.