0

Why does TCP socket.recvfrom() not return the sender address as it does with UDP?

When does TCP socket.recv() an empty string?

Thanks!

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
user3109117
  • 11
  • 1
  • 4

1 Answers1

2

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.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271