简体   繁体   中英

How to write response on IP address in TCP/IP socket programming

I have written a simple server to accept TCP connections and to read data from clients.

My question is: I have multiple clients with different IP addresses sending data on the same port. How can I write data to only one specific client by using its IP address?

I am assuming you have the file descriptors for the connected TCP sockets. It is easy to retrieve the addresses of the remote hosts.

The key is the getpeername() system call, which allows you to find out the address of the remote end of a socket.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM