PDA

View Full Version : QUdpSocket -- Rebinding with Different Port Numbers



swamyonline
22nd January 2009, 13:39
hi,
I have tried this and failed. At the start my application, I am creating a QUdpSocket and binding it with a port number and any_addr option. my application requires that, I have to change the port number with new one when the application is still running. Just before changing the port number, im disconnecting the socket from host and binding again with new port number and again establishing the connection for reading. but the same thing is not happening, the application, simply is not starting at all with all those options mentioned above.


application()
{
udpSocket = new QUdpSocket();
udpSocket->bind(portNum,QUdpSocket::ShareAddress);
QObject::connect(udpSocket,SIGNAL(readyRead()),SLO T(readData()));
}
in some other function, I am doing this to assign a new port number to the socket.

rebindPort(int newPortNum)
{
udpSocket->disconnectFromHost();
// udpSocket->abort();
udpSocket->bind(newPortNum,QUdpSocket::ShareAddress);
QObject::connect(udpSocket,SIGNAL(readyRead()),SLO T(readData()));
}

can I rebind the socket with a new port number like that? do i have to delete the socket and redo everything if i have to rebind the socket with a new port number as the application is running?
whats wrong with this. pls post a suggestion. thank u.

bye
swamy