[Qt-interest] How to change QUdpSocket peer port
Laurent Astart
laurent.astart at gmail.com
Tue Jan 10 10:38:46 CET 2012
2012/1/9 Konrad Rosenbaum <konrad at silmor.de>
> Hi,
>
> On Monday 09 January 2012, Laurent Astart wrote:
> > I'm searching for a way to change the peer port of a QUdpSocket, without
> > loosing my local port (that is no disconnection / reconnection).
>
> UDP has no connections.
Yeah, you're right, but QAbstractSocket does :
QAbstractSocket's API unifies most of the differences between the two
> protocols. For example, although UDP is connectionless, connectToHost<http://doc.qt.nokia.com/4.2/qabstractsocket.html#connectToHost>()
> establishes a virtual connection for UDP sockets, enabling you to use
> QAbstractSocket in more or less the same way regardless of the underlying
> protocol. Internally, QAbstractSocket remembers the address and port passed
> to connectToHost<http://doc.qt.nokia.com/4.2/qabstractsocket.html#connectToHost>(),
> and functions like read <http://doc.qt.nokia.com/4.2/qiodevice.html#read>()
> and write <http://doc.qt.nokia.com/4.2/qiodevice.html#write>() use these
> values.
In fact I would like to use the virtual connection given by the base class
AND be able to change the destination port. It could seem contradictory,
but I have a good reason doing so.
> If you use the writeDatagram methods to send UDP
> packets you can chose a differnt target and port for each packet.
>
It forbids the use of read() and write(), but it could do the trick. Thanks
for your answer.
Konrad
>
Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20120110/cbb3d629/attachment.html
More information about the Qt-interest-old
mailing list