Page 1 of 1

Error Message io is not defined

Posted: Thu Aug 02, 2012 3:41 am
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)

Re: Error Message io is not defined

Posted: Thu Aug 02, 2012 4:25 am
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.

Re: Error Message io is not defined

Posted: Thu Aug 02, 2012 10:51 am
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.

Re: Error Message io is not defined

Posted: Thu Aug 02, 2012 6:44 pm
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.