Error Message io is not defined

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
ShawnSwander
Posts: 53
Joined: Thu May 17, 2012 12:31 am

Error Message io is not defined

Post by ShawnSwander »

I'm trying to connect to my server from another computer it works fine when I connect from my server via http:\localhost and via the ip-address but I can't connect from another computer when I try I get the error message below... Here is my code and the error message.

Client side...

Code: Select all

<script src="http://localhost:8080/socket.io/socket.io.js"></script>
...
<script type="text/javascript">

var socket = io.connect('http://localhost:8080');    //(a) Error points here
Server side

Code: Select all

var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')
Error Message(s)

Code: Select all

Uncaught ReferenceError: io is not defined           ->points to (a)
(anonymous function)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Error Message io is not defined

Post by Jackolantern »

I can only help so much as I have not really worked deep into Node and Socket.io, but have you configured your server's firewall to allow connections on the ports you are having clients connect to? If not, your firewall is absolutely going to deny some random text-data connection to an atypical port.
The indelible lord of tl;dr
User avatar
OldRod
Posts: 1320
Joined: Sun Sep 20, 2009 4:26 pm

Re: Error Message io is not defined

Post by OldRod »

I just went through this last week trying to get my iPad to connect, so maybe I can help :)

From the client computer you can't use 'localhost' as that will try looping back to the localhost of the client computer.

You have to use the ipaddress of the host computer. Go to Start/Run and type 'cmd'. In the command window that opens, type 'ipconfig' to get the ipaddress of the host machine.

Also, on your host computer, you have to have your firewall open the port you are using. Whether it is Windows firewall or some 3rd party, there is probably something in the settings that lets you do that.

And lastly, on your host machine you need to edit a setting in your Apache httpd.conf file. Here is the section where I had to change:
#
# Controls who can get stuff from this server.
#

# onlineoffline tag - don't remove
Order Deny,Allow
# Deny from all
Allow from all
Comment out 'deny from all' and add 'allow from all'

That allowed me to connect any machine on my home network to the localhost of my host machine. I assume the same types of changes would have to be made in your environment, unless node/socket.io requires something else. Hopefully that helps.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Error Message io is not defined

Post by Jackolantern »

Ohh! I didn't even notice they were trying to connect to localhost on the client. Yes, unless the client is on the same computer as the server, that will always fail. You need to check your IP address and change it to that.
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”