I work on a client-server application for the first time using the Netty library, and if everything is easier with the server, it turned on and immediately waits for a connection, then with the client everything is different in my case. I do not know how best to make a request for technical information for work and a request for authorization of the user. I tried several options and in each I'm not sure.
- The most logical and simplest one that could have occurred to me was that when the program was started, one permanent connection was created, through which technical information was first requested, processed and then only, and if the user wants, you can authorize. The problem is only in one, it seems to me: it is not known how long it will take from the launch of the program to authorization, and all this time the connection should be established, and if the user launches many instances of the program, then what? - a lot of connections, an extra load and a timeout for the answer can not be put ...
- Attempting to avoid problems from the first paragraph suggested another idea - to establish a connection and then terminate it after the completion of the request, but this option immediately disappeared, because you need to get an answer through this connection. Yes, you can set a timeout to wait for a response, say, 5 seconds and not terminate the connection manually, and the problem with receiving the packet disappears, and a third appears ... it would be more logical to use an already established connection, if it is still alive than each just create a new one and recreate it in the case of a timeout.
In general, I would be satisfied with the second option, but I have problems with its implementation. And what do you advise?