问题描述
假设我有一个简单的winsock服务器,它有一个侦听socket,然后当一个连接被接受,它存储在套接字数组(允许多个连接)。如何获取特定连接的IP地址?它存储在套接字句柄中?
只要套接字保持连接,
getsockname 将给你本地名称(即从管道的一侧)getpeername strong>将给你对等名称(即管道的远端)
此信息仅在套接字打开/连接时可用,因此存储它在某处,如果它可以在对等体断开后使用。
Suppose I have a simple winsock server that has a listening socket, and then when a connection is accepted, it stores the socket in an array of sockets (to allow multiple connections).How can I get the IP address of a specific connection? Is it stored in the socket handle?
As long, as the socket stays connected, you can get both own socket address and peer one.
getsockname will give you local name (i.e. from your side of a pipe)getpeername will give you peer name (i.e. distant side of a pipe)
This information is available only when the socket is opened/connected, so it is good to to store it somewhere if it can be used after peer disconnects.
这篇关于winsock存储套接字的ip地址在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!