Answer the question
In order to leave comments, you need to log in
Socket server for multiple clients with a persistent connection. How?
I am making a socket server to which hundreds of clients should be connected with a persistent connection. The client is a device with sensors. which periodically sends statuses. Those. the amount of information is small. At the beginning of the connection, greetings are exchanged to make sure that it was not Uncle Vasya who knocked. Then statuses are sent periodically.
About sockets I read almost enough. The thing is pretty primitive. Very helpful in understanding this and this article. But some questions still remain.
1. Is a permanent connection possible?
The article at the second link says this:
But if you plan to reuse your socket for further transfers, you need to realize that there is no EOT on a socket. I repeat: if a socket send or recv returns after handling 0 bytes, the connection has been broken. If the connection has not been broken, you may wait on a recv forever, because the socket will not tell you that there's nothing more to read (for now).
Answer the question
In order to leave comments, you need to log in
1. Perhaps see TCP keepalive. It is necessary to correctly handle the socket of a failed client.
2. nginx.org/ru/#architecture_and_scalability + www.kegel.com/c10k.html It is
better to read Stevens about sockets.
Are you sure you need sockets?
If I understand correctly, clients only send their state to the server. In this case, if the frequency is low (more than 10 seconds), it might be better not to keep a constant connection, but to do everything through requests.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question