I am working on a web client which connects to a external server through a socket connection. Following are the two design approaches
Approach 1st:
Each request from a client opens a new socket connection to a server, sends request and process the response.
Problem: Too many socket connections
Approach 2nd:
There will be only one socket connection, all the client will send request through same connection.
Problem: Not sure how to map a response to a particular request, may be bit slower than approach first.
Approach 3rd:
Its more or same like 2nd approach, there will be only one socket connection between the client and external server, the only difference is for each client request a Runnable object will be created an submitted to the
thread pool, which again are going to use the same connection for sending request.
Problem: how to map the response with the request?
Can somebody help me in finding the best way (Or if there is any other way of designing this). More over how can I solve the problem mentioned for 2nd and 3rd approach if I take either of it as a solution?