This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple client sockets sharing port number

 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

one very basic question. I am starting in this field and the answer will clarify many things. Is it possible for a server to hold several client connections sharing the same port? (meaning the client socket, not the listening socket (serversocket)).
I have done some practice with some code pieces from the internet, and have seen that each time a new client connects, a new port number is assigned. I figure to think that the server might be bound to a concrete number of connections derived from its port capacity. So, then it arises the question, is it possible to use several connections in the same port number?.

At the beginning I thought Nooo.... , BUT since TCP ensures completion and that packages are received in the right order, perhaps I can build a logic in my program that allows me to separate packages corresponding to each connection.

On the other hand, if possible, how can I decide the port being shared. The serverSocket accepts the connection and creates a socket automatically without having the chance to specify a port number.

Many thanks in advance. Any help is greatly appreciated.

Carlos.



 
Paul Clapham
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it's a basic question, can I ask another basic question in return? Here it is: why do you want to know? You can certainly have multiple clients connected to the same server; they all use the same server socket but they all use different client sockets. This works perfectly well in practice, so it's not obvious why you want to interfere with the process.
 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul for your quick answer,

I don't think I ever need to implement such a solution, and probably is out of my scope right now.
However in case an application hosted in a server received huges amount of requests, in order to be able to attend them a different approach should be adopted isn't it?. I am not aware right now which amount of simultaneous connections can a regular server attend, but I guess other server architechtures are more suitable when such situations arise...

This is more a question for my knowledge rather than something I must do in real life.

Many thanks again.

Carlos.
 
Paul Clapham
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carlos Conti wrote:However in case an application hosted in a server received huges amount of requests, in order to be able to attend them a different approach should be adopted isn't it?


No, I don't think so. Why do you say that?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic