Re: [nodejs] Problem with using socket.io

1,374 views
Skip to first unread message

Dan Milon

unread,
Nov 1, 2012, 5:16:42 PM11/1/12
to nod...@googlegroups.com
Probably the browser (for some reason) did not fetch the socket.io.js
file, so the global variable "io" does not exist.

Make sure the server returns the file, and the client can talk to the
server.

danmilon.

On 11/01/2012 11:12 PM, _Kili_ wrote:
> Hi,
> I am beginner with node.js and just trying to make socket.io work with
> this guide http://socket.io/#how-to-use (the first example).
> I am just getting "Uncaught ReferenceError: io is not defined" in the
> java script console of the Chrome.
> Could someone help me?
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

Angel Java Lopez

unread,
Nov 1, 2012, 5:28:26 PM11/1/12
to nod...@googlegroups.com
Hmmm... you must open the index.html as
I guess you cannot start it as a local file

Chad Engler

unread,
Nov 1, 2012, 5:29:22 PM11/1/12
to nod...@googlegroups.com

You may get more response form the Socket.io mailing list:

 

sock...@googlegroups.com

 

-Chad

_Kili_

unread,
Nov 1, 2012, 6:01:11 PM11/1/12
to nod...@googlegroups.com
Thanks, I posted the same question to the correct group. I did not yet solve the problem with the help in the previous answers. Thanks for the quick replies.

John Fitzgerald

unread,
Nov 1, 2012, 6:18:38 PM11/1/12
to nod...@googlegroups.com
Try this for the html, loads socket.io from a CDN. (Works on my computer...)

<script>
  var socket = io.connect('http://localhost');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>
John R. Fitzgerald


_Kili_

unread,
Nov 2, 2012, 4:53:16 PM11/2/12
to nod...@googlegroups.com
Thanks John,
The io is now found but I am getting this:
XMLHttpRequest cannot load http://localhost:8080/socket.io/1/?t=1351888164983. Origin http://127.0.0.1:8080 is not allowed by Access-Control-Allow-Origin.

Angel Java Lopez

unread,
Nov 2, 2012, 5:04:42 PM11/2/12
to nod...@googlegroups.com
Hmmmm... Then, it's not the same example that you pointed initially, at http://socket.io/#how-to-use the port is 80.

What is the URL in your browser, when you launch the index.html?

_Kili_

unread,
Nov 3, 2012, 11:02:03 AM11/3/12
to nod...@googlegroups.com
Thanks guys,
It's working now. 
Reply all
Reply to author
Forward
0 new messages