Get Even More Visitors To Your Blog, Upgrade To A Business Listing >> connection only establishes on server reset (nodejitsu) works fine locally? connection only establishes on server reset (nodejitsu) works fine locally?


So basically I'm making a simple RTS board game with node.js/express/ for a learning experience. So far it's going really well and I though I was almost there working purely on the localhost. Deployed it to nodejitsu and loaded the page up, but the server isn't sending the initial server data to the client. If (while the page is open, no refresh) I reset the server it then establishes connection and the whole thing works as expected, but a client visiting the server doesn't do it.

Server init code:

    var express = require('express');
var app = require('express')()
  , server = require('http').createServer(app)
  , io = require('').listen(server);


app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res){



app.get('/RTSwords', function(req, res){



Server code

// define interactions with client
io.sockets.on('connection', function(socket){
    //send them board and first seven tiles.

    socket.emit('serverNews', {'game': JSON.stringify(gameBoard), 'newTiles': randomTileString(7)});

And client code

var socket = io.connect('http://MYURLHERE');
socket.on('serverNews', function(data){

So yeah,in summary it works locally, works when page is loaded and server is restarted (I'm just "jistu deploy"ing to do that) but not when server is running then page is loaded.

Any help would be much appreciated!


Problem courtesy of: tomatosource


On the client use io.connect() , if you need more help join #nodejitsu on IRC, or irc://

Solution courtesy of: blakmatrix


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post connection only establishes on server reset (nodejitsu) works fine locally?


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription