How client IP address and port knows to the server ?,
Ans: When datagram is recieved( readyRead signal is emited), you can use readDatagram API
socketServer.readDatagram(buffer.data(),buffer.size(),&sender,&port);
sender = IPaddress of client
por = portNumber of client.
Here is the solution using Qt's QUDPSocket, 1 UDP Sever, with multiple client on same local host, tested it is working. commented the code, wherever necessary
There are two console application( UDPServer and UDPClient )
How to test
1. Run UDPServer, it will listen on port 9999
2. Run UDPClient(First instance )
3. Run UDPClient(second instance )
Result:
Please check below screenshot

UDPServer Code
> main.cpp
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
UDPServer server;
return a.exec();
}
> UDPServer.h
#ifndef UDPSERVER_H
#define UDPSERVER_H
#include <QObject>
#include <QUdpSocket>
class UDPServer : public QObject
{
Q_OBJECT
public:
explicit UDPServer(QObject *parent = 0);
void WriteData( const QString& );
public slots:
void readReady();
private:
QUdpSocket socketServer;
};
#endif // UDPSERVER_H
> UDPServer.cpp
#include "UDPServer.h"
UDPServer::UDPServer(QObject *parent) :QObject(parent),socketServer(this)
{
qDebug()<<"I am UDP server, listening on 9999";
// Listen to 9999 port server
socketServer.bind(QHostAddress::LocalHost,9999 );
connect(&socketServer,SIGNAL(readyRead()),this,SLOT(readReady()));
}
void UDPServer::readReady()
{
QByteArray buffer;
buffer.resize(socketServer.pendingDatagramSize());
QHostAddress sender;
quint16 port;
socketServer.readDatagram(buffer.data(),buffer.size(),&sender,&port);
qDebug()<<"Datagram Recieved From";
qDebug()<<"Client IP" << sender.toString();
qDebug()<<"Client Port Number " << port;
qDebug()<<"\n\n";
// Write to the client,need to specify the client port number.
QByteArray clientData;
clientData.append( "data");
socketServer.writeDatagram( clientData, QHostAddress::LocalHost, port );
}
UDPClient Code
> main.cpp
#include <QtCore/QCoreApplication>
#include "udpclient.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
UDPClient client;
client.WriteData("What is my IP");
return a.exec();
}
> udpclient.h
#ifndef UDPCLIENT_H
#define UDPCLIENT_H
#include <QObject>
#include <QUdpSocket>
class UDPClient : public QObject
{
Q_OBJECT
public:
explicit UDPClient(QObject *parent = 0);
void WriteData( const QString& );
public slots:
void readReady();
private:
QUdpSocket clientSocket;
};
#endif // UDPCLIENT_H
> udpclient.cpp
#include "udpclient.h"
UDPClient::UDPClient(QObject *parent) :QObject(parent), clientSocket(this)
{
qDebug()<<"I am your client";
connect(&clientSocket,SIGNAL(readyRead()),this,SLOT(readReady()));
}
void UDPClient::WriteData(const QString& data)
{
QByteArray clientData;
clientData.append( data);
// write to the port, listening by the server.
qDebug()<<"Writing datagram to 9999 port";
clientSocket.writeDatagram(clientData, QHostAddress::LocalHost, 9999 );
}
void UDPClient::readReady()
{
// got response from server, so clientSoclet port number can get.
qDebug()<< "Reacieved response from server through my port(Client port No):" << clientSocket.localPort();
QByteArray buffer;
buffer.resize(clientSocket.pendingDatagramSize());
QHostAddress sender;
quint16 port;
clientSocket.readDatagram(buffer.data(),buffer.size(),&sender,&port);
// To read server IP
qDebug()<< "Server IP Responded" << sender.toString();
qDebug()<< "Server Port Number" << port;
}