0

What is the difference between the following scenario's. And is there any performance differ due to this.

Consider a server provide 5 services like web, mail, file, app and ssh :

  1. Each services and their corresponding port is binded with different sockets(Individual sockets for each service).
  2. A single socket is binded with all the services corresponding to the port it runs(Common socket for all services).
Rolf Rander
  • 3,221
  • 20
  • 21
mohangraj
  • 9,842
  • 19
  • 59
  • 94
  • You should look in to the comprehensive answers given to similar questions before: http://stackoverflow.com/questions/577885/uses-of-so-reuseaddr http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t http://stackoverflow.com/questions/3229860/what-is-the-meaning-of-so-reuseaddr-setsockopt-option-linux – Rolf Rander Jan 07 '16 at 11:32

1 Answers1

-1

Two separate processes cannot call bind() on sockets for the same protocol and address.

For a thorough explanation of the details, take a look at this previous answer: Socket options SO_REUSEADDR and SO_REUSEPORT, how do they differ? Do they mean the same across all major operating systems?

Community
  • 1
  • 1
Rolf Rander
  • 3,221
  • 20
  • 21
  • In UDP it is possible or not? – mohangraj Jan 07 '16 at 10:27
  • I think it's possible with udp, but you need to think hard about your protocol. Each udp-packet will reach all processes. What do you want to achieve? – Rolf Rander Jan 07 '16 at 10:29
  • No. Just for clarification. So, I need each independent socket for each services runs on my server. Is it right? – mohangraj Jan 07 '16 at 10:34
  • You most certainly can share sockets between processes. Consider, for example, a program that has a TCP connection as its standard input that then calls `fork`. And TCP ports aren't bound to processes, they're bound to sockets. – David Schwartz Jan 07 '16 at 11:00
  • @DavidSchwartz Is it possible to bind sockets to more than one port? – mohangraj Jan 07 '16 at 11:04
  • @mrg It is impossible to bind a socket to multiple ports. – PlushBeaver Jan 07 '16 at 11:19
  • @DavidSchwartz I see that my answer confuses "sockets" and "processes", but still: a call to socket(2) returns a descriptor which is an int that only refers to a socket within the context of the current process, how can that be shared between processes? And a call to bind(2) with an address already bound in another process returns EADDRINUSE. – Rolf Rander Jan 07 '16 at 11:26
  • @PlushBeaver Can you answer for my question? – mohangraj Jan 07 '16 at 11:32
  • @DavidSchwartz Can you answer for my question? – mohangraj Jan 07 '16 at 11:32
  • @mrg you should edit your question and provide some more information on what you want to achieve – Rolf Rander Jan 07 '16 at 11:37
  • @mrg I don't understand your question, so I can't answer it. I have no idea what "binded with all the services corresponding to the port it run" means. – David Schwartz Jan 07 '16 at 12:14
  • @RolfRander It can be shared between processes many ways. I explained one of them -- a process that has a TCP connection as its standard input calls `fork`. There are many others. – David Schwartz Jan 07 '16 at 12:15