• Post Reply Bookmark Topic Watch Topic
  • New Topic

Design for socket application  RSS feed

 
john sal
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john sal wrote: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


Why too many? How many will there be at one time? How many will be opened and closed per unit time?

Approach 2nd:
There will be only one socket connection, all the client will send request through same connection.


So all client requests are coming from one single process on one host then.

Problem: Not sure how to map a response to a particular request, may be bit slower than approach first.


Define your protocol such that each request includes a unique ID. Why do you think it will be slower?
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set up a socket connection pool.

Once the client is done with the Socket, return it to the pool.

WP
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!