Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 Qt 使用 QTcpServer 创建 TCP 服务器。每次客户端连接到服务器时,我都想知道远程主机的 IP 地址和端口号。我尝试搜索文档,但找不到有关此主题的任何信息。
我知道应该有办法,我只是无法弄清楚。请帮忙。
QTcpServer 不会直接在传入连接上告诉您地址/端口,但您可以通过从 QTcpServer::nextPendingConnection() 获取连接的 QTcpSocket 然后使用 QTcpSocket 的 peerAddress() 和 peerPort() 方法来获取它。