Get remote host Ip address QTcpServer
Asked Answered
P

1

7

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.

Pewter answered 9/2, 2012 at 0:58 Comment(0)
T
17

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.

Tanana answered 9/2, 2012 at 1:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.