PDA

View Full Version : QUdpSocket and ShareAddress



mdecandia
26th March 2007, 14:47
Hi all,
I'm using QUdpSocket in a client-server environment and I want to improve performance sharing listen port between more identical server processes.
All datagrams are processed by all processes but I want to split them between processes.
I used the bind mode SharedAddress to bind sockets to same port but nothing changed.
Server socket binding and datagram processing is done as follows:

------ Binding
udpSocket = new QUdpSocket();
udpSocket->bind(portNum,QUdpSocket::ShareAddress);
connect(udpSocket, SIGNAL(readyRead()),
this, SLOT(processPendingDatagrams()));

---- Datagram Processing Slot

void Receiver::processPendingDatagrams()
{
while (udpSocket->hasPendingDatagrams()){
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(), datagram.size());

}

}

Do you have experience with this?

Thanks,
Michele

high_flyer
26th March 2007, 15:13
are the servers all on the same machine?

mdecandia
26th March 2007, 15:58
Yes, they are.

high_flyer
26th March 2007, 16:39
so how do you want all of them to use the same port?

mdecandia
26th March 2007, 16:51
From Qt docs I've read this:

QUdpSocket::ShareAddress : Allow other services to bind to the same address and port. This is useful when multiple processes share the load of a single service by listening to the same address and port (e.g., a web server with several pre-forked listeners can greatly improve response time). However, because any service is allowed to rebind, this option is subject to certain security considerations. Note that by combining this option with ReuseAddressHint, you will also allow your service to rebind an existing shared address. On Unix, this is equivalent to the SO_REUSEADDR socket option. On Windows, this option is ignored.

I think this means that more services may share a unique port.

high_flyer
26th March 2007, 17:06
Well, I learned somethig today. :)
I can't help you though...