Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get client's IP address

Tags:

c++

qt

I am writing a client server program that server receive message from client. I want to see the client's IP address on the server side. How can I do this? I would be grateful if you could help me. Thanks

like image 380
Honey Avatar asked Dec 25 '22 11:12

Honey


1 Answers

Since you are using QTcpSocket, I think .peerAddress is what you are looking for.

class Server : public QTcpServer {...}

On accept

void Server::acceptConnection() {
  std::cout << "new connection!\n";
  client = nextPendingConnection();
  std::cout << client->peerAddress().toString();
}
like image 195
rjdkolb Avatar answered Jan 08 '23 22:01

rjdkolb