Skip to content

Conversation

@josephg
Copy link

@josephg josephg commented Jul 15, 2011

I've fixed a few bugs and stubbed out some code to make the socket.io-client work in nodejs.

var serverio = require('socket.io').listen(8001);

serverio.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

var clientio = require('socket.io-client');
var socket = clientio.connect('http://localhost:8001');
  socket.on('news', function (data) {
  console.log(data);
  socket.emit('my other event', { my: 'data' });
});
$ node test.js
   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 20119662592043775798
   debug - setting request GET /socket.io/1/websocket/20119662592043775798
   debug - set heartbeat interval for client 20119662592043775798
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket writing 5:::{"name":"news","args":[{"hello":"world"}]}
{ hello: 'world' }
   debug - websocket received data packet 5:1+::{"name":"newListener","args":["news"]}
   debug - websocket received data packet 5:::{"name":"my other event","args":[{"my":"data"}]}
{ my: 'data' }

@3rd-Eden
Copy link
Contributor

-1 this adds unneeded bloat to the regular client

@rauchg
Copy link
Contributor

rauchg commented Aug 2, 2011

If we simply add // if node we can merge this.

@bewa
Copy link

bewa commented Aug 7, 2011

+1 we need #208 to be fixed!

@mauricemach
Copy link

+1, need to test some socket.io code! :)

Added // if node to a topic branch, please let me know if you need anything else to merge this.

@3rd-Eden
Copy link
Contributor

3rd-Eden commented Aug 7, 2011

Personally, I don't like the way this patch works. Especially the code it adds to make /lib/socket.js working on the server. I personally prefer on fixing the root issues instead of adding a hack.

The main problems are that we expect that certain variables are global and always available, this code should just add a check to see that is the case. this can be used in stead of window and that would also allow us to see if there is a document in window (so we know that document is a global).

As adding node support seems to be a hot topic today I decided to roll my own patch based on the work of Joseph.

3rd-Eden@f4e8abd

This creates a much more flexible code base and attempts to fix the root issues that we have when we require client side code in node.

@mauricemach
Copy link

Much better indeed, less is more.

3rd-Eden added a commit to 3rd-Eden/Socket.IO that referenced this pull request Aug 7, 2011
Updated package.json
Fixed ineffecient document check
@3rd-Eden
Copy link
Contributor

3rd-Eden commented Aug 7, 2011

#274 landed with nodejs support

@3rd-Eden 3rd-Eden closed this Aug 7, 2011
@mauricemach
Copy link

Yay for testing! Thanks a lot.

@josephg
Copy link
Author

josephg commented Aug 8, 2011

Great stuff - thats much better, 3rd-Eden. :)

@onurcom
Copy link

onurcom commented Dec 21, 2014

Hi,
When I run 'node test.js', it permanently writes ' info - unhandled socket.io url'. Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants