How to create a realtime chat using socket.io with using multiple servers (multiple ip) - node.js

I have done to develope the socket.io realtime app. but this feature cant worked at loadbalance node installed servers like as diff ip.
this one is worked at only same server with same port only? here, data stored at server side like memcache & mongos

you can use redis as store with socket.io to load balance.
Basic demo here:
https://github.com/chirag04/socket.io-express-redis-demo

Related

beginner webrtc/nodejs issue connecting remote clients

I'm trying to develop a web application in nodejs. I'm using an npm package called "simple-peer" but i don't think this issue is related to that. I was able to use this package and get it working when integrating it with a laravel application using an apache server as the back end. I could access the host machine through it's IP:PORT on the network and connect a separate client to the host successfully with a peer-to-peer connection. However, I'm now trying to develop this specifically in node without an apache back end. I have my express server up and running on port 3000, I can access the index page from a remote client on the same network through IP:3000. But when I try to connect through webrtc, I get a "Connection failed" error. If I connect two different browser instances on the same localhost device, the connection succeeds.
For reference: i'm just using the copy/pasted code from this usage demo. I have the "simplepeer.min.js" included and referenced in the correct directory.
So my main questions are: is there a setting or some webRTC protocol that could be blocking the remote clients from connecting? What would I need to change to meet this requirement? Why would it work in a laravel/webpack app with apache and not with express?
If your remote clients can not get icecandidates, you need TURN server.
When WebRTC Peer behind NAT, firewall or using Cellular Network(like smartphone), P2P Connection will fail.
At that time, for fallback, TURN server will work as a relay server.
I recommend coTURN.
Here is an simple implementation of simple-peer with nodejs backend for multi-user video/audio chat. You can find the client code in /public/js/main.js. Github Project and the Demo.
And just like #JinhoJang said. You do need a turn server to pass the information. Here is a list of public stun/turn servers.

Is possible to React Native run a socket server?

I'd like to make a app with React-Native that's accept connections from another devices (Desktops or mobiles) through raw tcp sockets (like node's Net API) or WebSockets (like Socket.io). The point is that, socket server must be running on the React-Native's App.
I already tried Socket.io and react-native-tcp, it works when i make the server run on a nodeJS's application and the client on RN's app, but not the reverse.
When i try to import Socket.io and make it listen on a port, a error is raisen, because RN don't have node's http module. Just Socket.io/clients works.
I think that i'm doing something wrong, but is really possible to do that? and what is the best way?
Obs: I'm really new in RN's world.
No, we can't create a server although if we create a server we can't connect any other external applications to the server.
So create a server and deploy it in any could service then use it in your react-native app.

Horizontally scale socket.io with redis

I currently am creating a horizontally scalable socket.io server which looks like the following:
LoadBalancer (nginx)
Proxy1 Proxy2 Proxy3 Proxy{N}
BackEnd1 BackEnd2 BackEnd3 BackEnd4 BackEnd{N}
My question is, with socket-io redis module, can I send a message to a specific socket connected to one of the proxy servers from one of the backend servers if they are all connected to the same redis server? If so, how do I do that?
As you wan to scale socket.io server, and you have used nginx as load balancer, do not forget to setup sticky load balancing, othersie single connection will be connected to multiple server based on load balancer pass the connection to socket.io server. So better to use sticky load balancing
With the redis socket io adapter, you can send and receive message with one or more socket.io server with help of Redis Pub/Sub implementation.
if you tell me which technology is used for Proxy and Backend, i will let you know more information on this.
Using the socket.io-redis module all of your backend servers will share the same pool of connected users. You can emit from Backend1 and if a client is connected to Backend4 he will get the message.
The key for this working though with Socket.io is to use sticky sessions on nginx so that once I client connects, it stays on the same machine. This is because the way that socket.io starts with a WebSocket and several long polling threads, they all need to be on the same backend server to work correctly.
Instead of sticky sessions, you can change your client connection optons to use Websockets ONLY and this will remove the problems with the multiple connections to multiple servers as there will only be one connection, the single websocket. This will also make your app lose the ability to downgrade to long-polling instead of WebSockets.

How to create a sails.js app that will listen on two different ports simultaneously

For example, I have a sails.js application that (by default) listens on port 1337. I want to configure it to listen on two different ports at the same time - one for SSL and one for non-SSL traffic. Is this even possible? I have scoured the documentation and cannot find an example that shows me anything other than setting a single port value.
Do I have to create an front-end that (like Apache or nginx) to do it is it it possible to stick with a pure node.js solution - perhaps with express?
I should add that I am only using the server for web sockets via socket.io
A working example would be great, but any tips and pointers would help.
the simplest would probably be to run your server twice.
Just make sure you share common data like sessions and persistent global variables - maybe using something like redis (sails can automatically base your session on redis and can even bind a model on the redis server while keeping the rest on your current database)

Node.js server as both a Socket.io host and client

For historical reasons and technical necessity our app has the following configuration:
The node.js workers need to connect (using Socket.IO-Client) to the node.js database access point AND listen for a connection from the node.js servers (using Socket.IO). I am having issues getting both to connect and I am wondering, do I need to use different ports for each Socket.IO-client or can they operate on the same port?
Right now, things seem to connect for a moment, but no data is passed along.
Adding larger version of the image: Larger Image

Resources