我正在编写一个客户端服务器程序,服务器接收来自客户端的消息。 我想在服务器端看到客户端的IP地址。我该怎么做? 如果您能帮助我,我将不胜感激。 谢谢
我正在编写一个客户端服务器程序,服务器接收来自客户端的消息。 我想在服务器端看到客户端的IP地址。我该怎么做? 如果您能帮助我,我将不胜感激。 谢谢
由于您正在使用QTcpSocket
,我认为.peerAddress
是您要寻找的内容。
class Server : public QTcpServer {...}
接受时
void Server::acceptConnection() {
std::cout << "new connection!\n";
client = nextPendingConnection();
std::cout << client->peerAddress().toString();
}