struct sockaddr_in s;
int len = sizeof(s);
int nRes = getpeername(perIoContext->sClient, (struct sockaddr FAR *)&s,&len);
if(nRes == SOCKET_ERROR)
{
cout << "获取错误" << endl;
}
else
{
cout << inet_ntoa(s.sin_addr) << s.sin_port << endl;
}
int len = sizeof(s);
int nRes = getpeername(perIoContext->sClient, (struct sockaddr FAR *)&s,&len);
if(nRes == SOCKET_ERROR)
{
cout << "获取错误" << endl;
}
else
{
cout << inet_ntoa(s.sin_addr) << s.sin_port << endl;
}
转载于:https://blog.51cto.com/fireflyliu/132536