Is it possible to connect Node.js and RED5? - node.js

I have the following problem.
I have a chat developed with ActionScript3 (AS3), SharedObjects (SO) and RED5. Well, this works correctly. Now, I'm developing a chat using Node.js, and this works correctly too.
My question/problem is how can I connect these 2 chats. Is it possible to send messages between Node.js and RED5? I want that one user that is chatting using Node.js chat and another user that is chatting using RED5 chat, can chat together.
Someone knows some solution? It's possible?

You need to code some server side servlet in Java to proxy your Node.js messages to and from the red5 chat.
Are you familiar with the Red5 API and have some understanding of the Java Servlet Container ? Cause you will need that to implement a solution.
Red5 is a server side technology that runs in the Tomcat Servlet Container. Propably Node.js could send a message to red5 via a simple servlet, that will then forward the message to all connected clients.
The other way round you could catch all chat messages on Red5 server side and then forward the messages to Node.js (however I don't know what incoming message receiver's you can code in Node.js).
Sebastian

Related

How to implement Laravel, node.js, socket.io and redis for creating realtime chat/notifications with database

I spend already 3 days for reading, watching tutorials about WebSockets, socket.io, node.js and so on.
Basically, I'm a Laravel developer and have just a basic idea about all the rest components.
With regret, after these 3 days I don't have in mind all logic step-by-step of implementing this architecture. I will try to explain what did I understand and you please correct me.
So :
WebSockets - is a bidirectional continuous connection between client and server. It uses another port, and basically it is not a HTTP/S connection.
For making this kind of app like I said, we need one more server, and idk why, but this is Node.js. At this Node.js server we should install socket.io (server-side package) and Redis.
Then, we need to add client-side socket.io (via CDN probably).
At Node.js server we are creating a server.js file where require all modules that we need, like socket.io and Redis. We open a connection for a specific non-used port (as 6001). Then we run this node server.
At front-end we are subscribe-ing to this channel and define method for emitting and listening to the server.
Example :
User1 is connecting to a specific route. User2 as well. User1 type a message for User2, when press Submit, message from User1 is sent to Node.js server, where it is sent in Redis(yes? if yes - Why?), and then Node.js is listening for what to do in this case, and send this message to specific user, or with broadcast to all users except the publisher.
Oh, it's even hard to explain that, too much steps and tehcnologies used.
Can please someone correct my logic? I really want to understand all that process and logic of using this components. Or please, give me some useful articles and videos, may be I didn't saw them. Thanks!
I suggest you read the official docs on how to build chat. Basically what you will have in the end is 2 servers, 1 for your Laravel app and the other for chat (Socket.io) . The key to this is using broadcasters and listening for events on both sides, frontend and backend.
Events are broadcast over "channels", which may be specified as public or private. Any visitor to your application may subscribe to a public channel without any authentication or authorization; however, in order to subscribe to a private channel, a user must be authenticated and authorized to listen on that channel.

Message app with node.js and socket.io

I am making a chat app with node.js and socket.io and need to save messages sent so anybody who did not see the chat can see it if they log on later. I only want the messages to be saved for 5 hours. Any Ideas
A possible solution is using Redis. Here is a client for node from GitHub.

Chat integration to existing Spring based application [Web + Mobile]

We are having existing Web application in Spring MVC. We are using Tomcat server. Also we have mobile app [Androis and iOs] for the same which is using spring based rest services. Now, we want to integrate chat functionality to both mobile and web application. I came across Socket.io and Node.js, which seems good. But, I am not much aware of these two frameworks. Then I came to know about Spring WebSocket.
Few Questions :
Which way is better to implement chat for existing spring based web
and mobile applications ? - Spring Websocket / Socket.io - Node.js
If we are going with Socket.io and Node.js, then how could I
configure the node.js to listen to my existing tomcat server port ?
Or I need to use separate port for client server communication for
chat functionality. [Because I tried to use same port, it was giving
Error: listen EADDRINUSE :::9090]
Any example would be the great help.
TIA.
Here is the sample application that sends messages back and forth,
Socket.io is used on client side to subscribe to a Topic of the server side.
Similarly you can use Sock.js with stomp client at client side and Spring on server side which provides an easy configuration with STOMP and also message handler annotation such as
#MessageMapping annotation which ensures that if a message is sent to destination mapping say "/hello" then the method associated with it should be called.
#SendTo annotation which is used to specify the value on which the returned message will be broadcast.
#Example stomp with spring for sending messages.

Is socket.io implementation possible inside REST framework?

I am building an app in which I provide functionality X, Y and chat.
Lets say that X and Y are non-interactive eg. reading articles - which will work fine with REST (on a node.js server) while chat is obviously interactive so it will work best with socket.io!
Questions: 1. Is it possible for me to 'switch on' a socket between the server and the user when the user navigates to the chat part of the application? 2. Can I open up a socket inside a GET request for the url: example.com/chats/usr_id on the node.js server?
3. How can this be accomplished inside a Backbone routing framework?
Yes. Just initialize the connection when the view is rendered (via a controller or script). See socket.io client documentation. You can just connect when the view is rendered and disconnect when the view is terminated. http://socket.io/docs/client-api/
You cannot open sockets with a GET request. Socket.io has it's own build in mechanisms for connecting to a socket server. It will start with Web Socket protocol and fall back to Long Polling. You can however use custom url's for unique things. One again, consult the socket.io documentation: http://socket.io/docs/client-api/
http://www.sitepoint.com/chat-application-using-socket-io/
p.s. I'd suggest reading up on how Web Sockets work, as you don't seem to have a very strong understanding.

how to distribute socket.io

Im using nodejs and socket.io to deliver a chat on my business app, but i want to distribute the deploy so i can have as many chat servers i want to balance the load of the traffic.
I try the load balance approach from nginx but that just do that balance the traffic but the communication between the socket.io serves its not the same, so one chat message send from user A to server S1 wont travel to user B on server S2.
There is any tool or approach to do this.
Thanks in advance.
===== EDIT =====
Here is the architecture of the app.
The main app frontend on PHP CodeIgniter lets tag it as PHPCI
The chat app backend on NodeJs and SocketIO lets tag it as CHAT
The chat model data on Redist lets tag it as REDIST
So what i have now its PHPCI -> CHAT -> REDIST. That work just fine.
What i need is to distribute the application so i can have as many PHPCI or CHAT or REDIST i want, example
PHPCI1 CHAT1
PHPCI2 -> -> REDIST1
PHPCI3 CHAT2
Where the numbers represent instances not different apps.
So a User A connected to PHPCI1 can send a message to a user B connected on PHPCI3.
I think some queue in the middle of CHAT can handle this something like rabbitmq that can only use the SocketIO to deliver the messages to the client.
If you're distributing the server load (and that's a requirement), I'd suggest adding a designated chat data server (usually an in-memory database or message queue) to handle chat state and message passing across edge servers.
Redis Pub/Sub is ideal for this purpose, and can scale up to crazy levels on even a low-end machine. The Redis Cookbook has a chapter on precisely this use case.
If you set up the server-side of your chat app correctly, you shouldn't have to distribute socket.io. Since node.js is browser-based and doesn't require any client-side code (other than the resources downloaded from the webpage), it works automatically. With a webpage, the files required to run socket.io are temporarily downloaded to users when they are correctly included (just like with jQuery). If you are using node.js and socket.io to make an android app, the files should be included in your application when you distribute it, not separately.
In addition, if you wish to use two separate socket.io servers, you should be able to establish communication between the two by connecting them in a similar manner that a client connects to the server, but with a special parameter that lets the other server know that a server connected and it can respond and set a variable for the other server.

Resources