TCP recvfrom() doesn't store 'from'

前端 未结 2 462
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 04:15

I\'m making a server program using TCP and I want to get the IP adress of the sender of the message I just received. Here\'s my code:

case FD_READ:
{    //In         


        
相关标签:
2条回答
  • 2020-12-22 04:34

    For a connected TCP socket, you should use getpeername() to obtain the address of the remote socket.

    0 讨论(0)
  • 2020-12-22 04:46

    TCP is a connection-oriented protocol. from and fromlen are meant to be used with connectionless protocols, such as UDP. According to the documentation, recvfrom ignores from and fromlen for connection-oriented sockets.

    0 讨论(0)
提交回复
热议问题