Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io connection url?

Tags:

socket.io

I have the current setup:

  1. Nodejs Proxy (running http-reverse-proxy) running on port 80.
  2. Rails server running on port 3000
  3. Nodejs web server running on port 8888

So any request starting with /nodejs/ will be redirected to nodejs web server on 8888.

Anything else will be redirected to the rails server on port 3000.

Currently Socket.io requires a connection url for io.connect.

Note that /nodejs/socket.io/socket.io.js is valid and returns the required socket.io client js library.


However, I am not able to specify connection_url to /nodejs/ on my server.

I have tried http://myapp.com/nodejs and other variants but I am still getting a 404 error with the following url http://myapp/socket.io/1/?t=1331851089106

Is it possible to tell io.connect to prefix each connection url with /nodejs/ ?

like image 781
disappearedng Avatar asked Mar 15 '12 22:03

disappearedng


People also ask

How do I connect to a Socket.IO server?

listen(port); // Create a Socket.IO instance, passing it our server var socket = io. listen(server); // Add a connect listener socket. on('connection', function(client){ console. log('Connection to client established'); // Success!

What is Socket.IO path?

path ​ Default value: /socket.io/ It is the name of the path that is captured on the server side.

Does Socket.IO use HTTP?

js) and the Socket.IO client (browser, Node. js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.

Is Socket.IO TCP connection?

The Socket.IO library keeps an open TCP connection to the server, which may result in a high battery drain for your users.


2 Answers

As of Socket.io version 1, resource has been replaced by path. Use :

var socket = io('http://localhost', {path: '/nodejs/socket.io'}); 

See: http://blog.seafuj.com/migrating-to-socketio-1-0

like image 198
supershnee Avatar answered Sep 19 '22 12:09

supershnee


you can specify resource like this:

var socket = io.connect('http://localhost', {resource: 'nodejs'}); 

by default resource = "socket.io"

like image 22
Sirian Avatar answered Sep 19 '22 12:09

Sirian