C++ 如何获得客户';IP地址

C++ 如何获得客户';IP地址,c++,qt,C++,Qt,我正在编写一个客户机-服务器程序,服务器从客户机接收消息。 我想在服务器端查看客户端的IP地址。我该怎么做? 如果你能帮助我,我将不胜感激。 谢谢因为您使用的是qtcsocket,我想peerAddress就是您想要的 class Server : public QTcpServer {...} 接受 void Server::acceptConnection() { std::cout << "new connection!\n"; client = nextPendin

我正在编写一个客户机-服务器程序,服务器从客户机接收消息。 我想在服务器端查看客户端的IP地址。我该怎么做? 如果你能帮助我,我将不胜感激。
谢谢

因为您使用的是
qtcsocket
,我想
peerAddress
就是您想要的

class Server : public QTcpServer {...}
接受

void Server::acceptConnection() {
  std::cout << "new connection!\n";
  client = nextPendingConnection();
  std::cout << client->peerAddress().toString();
}
void服务器::acceptConnection(){

std::你能提供更多关于你正在使用哪个库进行客户端连接的信息吗?例如,你正在使用哪个库?看看我在QTcpsocket上使用的@rjdkolb。我想你正在寻找的是peerAddress:@rjdkolb post作为答案。