Reputation: 11
Why does TCP socket.recvfrom()
not return the sender address as it does with UDP?
When does TCP socket.recv() an empty string?
Thanks!
Upvotes: 0
Views: 2910
Reputation: 136256
Why does TCP
socket.recvfrom()
not return the sender address as it does with UDP?
Because once a TCP connection is established that address does not change. That is the address that was passed to connect
or received from accept
calls. You can also find out the peer's address (if you lost it somehow) with getpeername
.
When does TCP socket.recv() an empty string?
When the peer has closed the connection and no more data will be coming in. You can still send data though because TCP connections can be half-closed.
Upvotes: 2