Can two applications on the same machine bind to the same port and IP address? Taking it a step further, can one app listen to requests coming from a certain IP and the other to another remote IP? I know I can have one application that starts off two threads (or forks) to have similar behavior, but can two applications that have nothing in common do the same?
相关问题
- Multiple sockets for clients to connect to
- Drakma and Dexador both fails at USocket call whil
- difference between file descriptor and socket file
- Port of the Rails app when running Cucumber tests
- Can we create a Silverlight Socket Server ONLY usi
相关文章
- Socket编程 TCP方式发送时间有点长
- socket() returns 0 in C client server application
- Passing extra metadata to a RequestHandler using p
- How do I get the external IP of a socket in Python
- Native hooking in Android Client
- Is zeroing out the “sockaddr_in” structure necessa
- How many times will TCP retransmit
- Does the TCPServer + BaseRequestHandler in Python&
Another way is use a program listening in one port that analyses the kind of traffic (ssh, https, etc) it redirects internally to another port on which the "real" service is listening.
For example, for Linux, sslh: https://github.com/yrutschle/sslh
For TCP, no. You can only have one application listening on the same port at one time. Now if you had 2 network cards, you could have one application listen on the first IP and the second one on the second IP using the same port number.
For UDP (Multicasts), multiple applications can subscribe to the same port.
If by applications you mean multiple processes then yes but generally NO. For example Apache server runs multiple processes on same port (generally 80).It's done by designating one of the process to actually bind to the port and then use that process to do handovers to various processes which are accepting connections.
I have tried the following, with
socat
:And even though I have not made a connection to the socket, I cannot listen twice on the same port, in spite of the
reuseaddr
option.I get this message (which I expected before):
Yes and no. Only one application can actively listen on a port. But that application can bequeath its connection to another process. So you could have multiple processes working on the same port.
You can make two applications listen for the same port on the same network interface.
There can only be one listening socket for the specified network interface and port, but that socket can be shared between several applications.
If you have a listening socket in an application process and you
fork
that process, the socket will be inherited, so technically there will be now two processes listening the same port.