Michael Joseph Aubry
Michael Joseph Aubry

Reputation: 13402

Socket.io with two node apps?

I am serving my main website with express and node.js, this gives me tremendous flexibility with my site.

I also have a back end app which runs on a separate node.js server, I think I may consider just combining it all into one, that strikes up some problems though and I like them being abstracted.

The only real issue I have had is socket.io communication between the two. On the front end site, a user can login/signup to the site and has access to a chat box that has limited features, just limited to a quick chat module.

The user object and any messages are sent to the same DB as the backend app, so the two share the same data, but the real time events don't work as both are loading different client side scripts.

So my question is what should I do to allow the two node.js servers/clients communicate with websocket events?

I tried within my site loading the socket.io script from my app

<script src="http://app.example.com/socket.io/socket.io.js"></script>

for some reason I get

// adds :3000 ??
GET http://app.example.com:3000/socket.io/1/?t=1420321032701 net::ERR_CONNECTION_REFUSED

Upvotes: 0

Views: 340

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146014

but the real time events don't work as both are loading different client side scripts.

I don't think the problem is the client side javascript code, it's the fact that the server instances don't share a common message bus.

So my question is what should I do to allow the two node.js servers/clients communicate with websocket events?

You need to read the using multiple nodes section of the docs and set up something like redis to server as the pub/sub central hub.

Upvotes: 1

Related Questions