Bahramdun Adil
Bahramdun Adil

Reputation: 6089

Which one is better, 3 ServerSocket each processing 1 requests OR 1 ServerSocket process 3 requests

I want to write an application in Java which will receive three requests at the same time continuously, then in the figure below which way is better and why to write the code or is there any other way better then these two? Thanks enter image description here

Upvotes: 1

Views: 53

Answers (2)

shazin
shazin

Reputation: 21923

If for each Request the processing of the request is same, then it is better that you use the same port with multiple threads to process it.

The usual practice is that for each functionality to have a different port in a system. For example FTP - Not Secured, SFTP - Secured.

Upvotes: 2

user207421
user207421

Reputation: 311050

It hardly makes any difference. All the activity with the ServerSocket itself is concerned with accepting connections and starting threads. There's no need for three ServerSockets and three threads to do this. In any case as they will all be listening to different ports, which one gets used is determined by the client, so it's pretty pointless: all clients could end up using only one of the ServerSockets.

Upvotes: 3

Related Questions