1

Can there ever be more than one program running on a single port? In other words, can two applications on the same server have the same port number?

nosid
  • 48,932
  • 13
  • 112
  • 139
Spaced
  • 55
  • 5
  • Try running `new ServerSocket(10000);new ServerSocket(10000);` – Sotirios Delimanolis Mar 02 '14 at 21:02
  • possible duplicate of [Socket options SO\_REUSEADDR and SO\_REUSEPORT, how do they differ? Do they mean the same across all major operating systems?](http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t) – Jason C Mar 02 '14 at 21:18

2 Answers2

3

If they're bound to different IPs, yes. Binding to a port binds to both a IP address and a port number. So if application A is bound to 192.168.0.56:25565, and application B is bound to 127.0.0.1:25565 they'll be no issue. But if application C wants to bind to either of those, or bind to 0.0.0.0:25565, it'll be given a error.

Zoey Mertes
  • 3,139
  • 19
  • 23
2

For TCP: Yes, as long as they are bound to different interfaces (e.g. eth0 and loopback). On the same interface, no.

For UDP: Yes.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • If I remember right, this is true for TCP, but not for UDP, but my recollection might be wrong. – jpw Mar 02 '14 at 21:06