Tolgay Toklar
Tolgay Toklar

Reputation: 4343

I am getting "io is not defined" error

I am using this on the client

<script type="text/javascript" src="http://domain.com:8440/socket.io/socket.io.js"></script>

When the server is too busy, sometimes it gives an "io not defined" error on the client. How can I resolve this ?

Here is my server code

var db_helper = require("./db.js");
var io=require('socket.io').listen(8440);
var check = require('validator').check,
    sanitize = require('validator').sanitize;
var roomid=0;
var anonid;
var ilet;
var userip;
var blck_id;

  io.set('transports', [

  , 'xhr-polling'
  , 'websocket'
  , 'jsonp-polling'
  ]);

The server has 16 GB RAM and 13.6 GHz CPU.

Upvotes: 0

Views: 439

Answers (3)

Chandu
Chandu

Reputation: 4561

Try this out,

get the clientside socketio library and put it in the folder from where the js files are served. Point the script location to this file location.

You will find the client side script here

 <server node_modules>\socket.io\node_modules\socket.io-client\dist\socket.io.js

In the first place, as pointed by @Timothy try to find out why the node is getting busy.

Upvotes: 1

Kurt Pattyn
Kurt Pattyn

Reputation: 2798

You can try to serve the socket.io.js file from a regular web server, as Chandu pointed out. This should at least offload the node.js server from that load.

Secondly - and this is more important - look at what is blocking your node.js server. As node.js is single threaded, you should by all means avoid long-running operations. Can you give an example of the code you are running in node?

Upvotes: 0

Timothy Strimple
Timothy Strimple

Reputation: 23070

Keep in mind node.js apps run in a single thread unless you're using something like Cluster to run more. This means that if you're doing something that blocks, it's possible for the requests to http://domain.com:8440/socket.io/socket.io.js to timeout, which would cause your io not defined error. You should see a 404 error in your console logs as well if / when this happens.

Upvotes: 3

Related Questions