user2449798
user2449798

Reputation: 444

Connect socket.io to different address

I'm developing a django system that has a build in chat that's been build with socket.io.

Today I was trying to get everything on webfaction so I registered the django part to http://example.com and the node/socket part to http://example.com/chat.

I have already managed to serve socket.io.js to the browser, but the connections are not working. The client is trying to connect to http://example.com instead of http://example.com/chat so I'm getting this error:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://example.com/socket.io/?EIO=3&transport=polling&t=1421523295233-0

On the client side I wrote this var socket = io.connect('http://example.com/chat/') to establish the connection

And on the server I wrote this:

var express = require('express');
var app = express()

var http = require('http');
var server = http.createServer(app).listen(20964, "127.0.0.1");

var io = require('socket.io')(server);

Using the server IP Address is no possible as it might change in the future.

What am I doing wrong here?

Thanks

Upvotes: 2

Views: 1481

Answers (1)

nkzawa
nkzawa

Reputation: 211

You have to set the path option on client:

io('http://example.com', {path: '/chat/socket.io'});

This is because socket.io client tries to connect to /socket.io by default, but in your case, it's hosted under /chat, thus you have to change the setting of where socket.io connects with the option.

Upvotes: 2

Related Questions