How to force TcpNetClientConnectionFactory to open a connection without sending a message? - spring-integration

I have a task to create a Spring-integration TCP client which should connect to a server and receive messages from it:
The server is responsible for sending "heartbeat" and data messages and doesn't expect any incoming messages from the client, except acknowledgements.
The client must open and maintain (reopen) a connection to the server.
As I understand, TcpNetClientConnectionFactory opens a connection only upon sending a message. Is there any way to open a connection without sending any data (something like SocketFactory.createSocket(host, port) does) and maintain it?

Please, investigate a TcpReceivingChannelAdapter and let us know why it doesn't work for you:
https://docs.spring.io/spring-integration/docs/current/reference/html/ip.html#tcp-adapters

Related

nodeJS how to send a message with connection request

I am using websockets to talk with server but I want to prevent client from connecting if a requirement is not met. My code is very simple
let socket = new WebSocket('wss://server.com/server/');
socket.addEventListener('open', function(e) {
// we are now connected
});
How does nodeJS connect? It must send a connect message right? Is there a way to edit that message? I'd like to limit it so connections can not be made unless a key is sent with the connection message.
How it works now I send a "login request message" and if the credentials dont match I terminate the connection but currently people could still open connections without sending the login request. This would be a security issue right? People could just DDOS by creating a bunch of connections without logging in.
It's not NodeJS's responsibility to manage DOS/DDOS requests. That is done at the network layer (routers, switches, load balancers, proxies, etc.). See this answer for more detail: protection agains DOS websocket with ip address
Preventing users from continuing to communicate over the socket can be done after a successful connection is made and then the key sent, after which, if it's marked as valid by the server, it continues, otherwise it closes the connection. The limits on how many times a client can connect (or in this case re-connect) are handled by the network rules.

Is it possible to have server to server communication with websockets?

I'm trying to have 2 servers communicate with each other, I'm pretty new to websockets so its kind of confusing. Also, just to put it out there, i'm not trying to do this: websocket communication between servers;
My goal here is to basically use a socket to read data from another server (if this is possible?) I'll try to easily explain more below;
We'll assume there is a website called https://www.test.com (going to this website returns an object)
With a normal HTTP request, you would just do:
$.get('https://www.test.com').success(function (r) {
console.log(r)
})
And this would return r, which is an object thats something like this {test:'1'};
Now from what I understand with websockets, is that you cannot return data from them because you don't actually 'request' data, you just send data through said socket.
Since I know what test.com returns, and I know all of the headers that i'm going to need, is it possible to just open a socket with test.com and wait for that data to be changed without requesting it?
I understand how client-server communication works with socketio/websockets im just not sure if its possible to do server-server communication.
If anyone has any links to documentation or anything trying to help explain, it would be much appreciated, I just want to learn how this works. (or if its even possible)
Yes, I you can do what (assuming I understood your needs correctly). You can establish a websocket connection between two servers and then either side can just send data to the other. That will trigger an event at the other server and it will receive the sent data as part of that event. You can do this operation either direction from serverA to serverB or vice versa or both.
In node.js, everything is event driven. So, you would establish the webSocket connection and then just set up an event handler to be triggered when data arrives. The other server can then just send new data whenever it has updated data to send. This is referred to as the "push" model. So, rather than serverA asking serverB is it has any new data, you establish the webSocket connection and serverB just sends new data to serverA whenever that new data is available. Done correctly, this is both more efficient and more timely (as there is no polling interval and no cycles wasted asking for data when there is nothing new).
The identical model can be used between servers or client to server. The only difference with the client/server model is that the webSocket must be initially established client to server. With the server to server model, either server can initiate the connection.
You can think of a webSocket connection like establishing a phone call. Once the phone call is established, either side can just say something and the other end hears what they're saying. The webSocket connection is similar. Once its established, either side can just send some data to the other end and the other end will receive it. It's an open pipeline ready to have data sent either way. In node.js, when data arrives on that pipeline, it triggers and event so the listener will get that event and see the data that was sent.

Node.js: Use an existing TCP Socket in a different proccess

I'm developing a Gateway with Node.js and I'm having some issues. I have the following situation:
A TCP socket (net module) receives a connection from a client, parses the message and writes in a RabbitMQ queue which is read by another service.
This other service receives the message and sends a confirmation message to another RabbitMQ queue, which is read by a worker written in Node (rabbit.js).
In this worker, I'll read the queue, parse a response and send it to the client via the previous TCP connection which is still open.
The problem is, I don't know how to reuse the socket already created (considering that the conection doesn't have any problems and is still alive)
Is there's a way to reuse a TCP socket in another proccess that way?
Thanks a lot.

How to send message after user's socket disconnect from the server

I'm using net module of node.js to build a chat server based on TCP. I have figured out how to handle the situation where two users both connect to the server. However, for a chat app, even if the user disconnect from the internet, people can still send message to those disconnected users. I just have no idea of how to achieve this.
You need to save messages in a database so that when they log in again you can retrieve sent messages and send them all at once.
There is no way to communicate to a user who has logged off. You just have to queue up the messages and deliver them when they reconnect.

negative ack from socket.io

I am using socket.io to send data from my sever to clients. There are situations when a client looses its connection but the server gets to know about this only when the next heartbeat is not recieved from the ckient.
the messages that are sent between the client loosing its network connection to the time when the sever derives this from absense of heartbeats are lost and I am not able resend them when the client rconnects.
I know there I can send a callback in my message which the client will call on successfull delivey of message. however this callback is asynchronous and I Am not aware of any way by which I can getto know that the message delivery failed. Can anyone please help me findhow can I capture a failure to delive a message.
Thanks in advance
According to the documentation, you can configure "max reconnection attempts" for
How many times should Socket.IO attempt to reconnect with the server after a a dropped connection. After this we will emit the reconnect_failed event.

Resources