So I wonder - is it possible to pass accepted TCP connection (on Windows or Unix like OS) from one process to another? Here the point is to pass connection - not data in a way a proxy app would.
The client sends a FIN packet to the server and updates its state to FIN-WAIT-1. The server receives the termination request from the client and responds with an ACK. After the reply the server will be in a CLOSE-WAIT state. As soon as the client receives the reply from the server, it will go to the FIN-WAIT-2 state.
What is the maximum number of concurrent TCP connections that a server can handle, in theory ? A single listening port can accept more than one connection simultaneously. There is a '64K' limit that is often cited, but that is per client per server port, and needs clarifying.
1 Answer. Save this answer. Show activity on this post. Two processes cannot bind (and listen) to the same unix socket.
For TCP, no. You can only have one application listening on the same port at one time.
In Unix, a TCP connection is represented as a socket file descriptor. When you fork
a process, the file descriptors are inherited by the child process, including TCP sockets. (Though they may be closed on exec
if given the FD_CLOEXEC
flag with fcntl
.)
It's also possible to transfer file descriptors between unrelated processes using a local (Unix) domain socket; see this question.
I'm not sure about Windows.
On Windows, use WSADuplicateSocket
, pass the filled in WSAPROTOCOL_INFO
to the other process, use WSPSocket
to recreate a socket.
On unix-like OS'es this is possible using the sendmsg()
system call. libancillary abstracts this for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With