本文介绍了获取远程主机IP地址QTcpServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Qt使用QTcpServer创建TCP服务器.每次客户端连接到服务器时,我想知道远程主机的IP地址和端口号.我尝试搜索文档,但找不到有关此主题的任何信息.

I'm using Qt to create TCP server using QTcpServer. Every time a client connects to server, I would like to know the remote host's IP address and port number. I tried searching documentation but couldn't find any information on this topic.

我知道应该有办法,我只是无法弄清楚.请帮助.

I know there should be a way, I'm just not able to figure it out. Help please.

推荐答案

QTcpServer不会直接在传入连接上告诉您地址/端口,但是您可以通过从QTcpServer :: nextPendingConnection()获得连接的QTcpSocket来获得它.然后使用QTcpSocket的peerAddress()和peerPort()方法.

QTcpServer won't tell you the address/port directly on an incoming connection but you can get it by getting the connected QTcpSocket from QTcpServer::nextPendingConnection() and then using QTcpSocket's peerAddress() and peerPort() methods.

这篇关于获取远程主机IP地址QTcpServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-18 19:58