Results 1 to 7 of 7

Thread: forcing local port number from TcpSocket?

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default forcing local port number from TcpSocket?

    is there are method to force the local port number when making a tcp connection?

    for example, i am connecting to an RSH service to port 514, but i need the source port to be 1023...

    Qt Code:
    1. void Process::connectToRsh()
    2. {
    3.  
    4. blockSize = 0;
    5. tcpSocket->abort();
    6. tcpSocket->connectToHost(ui.IpAddressLineEdit->text(),514);
    7. ui.ResultsTextEdit->append(tr("connecting"));
    8. }
    To copy to clipboard, switch view to plain text mode 

    So its easy to see how to connect to port 514, but what about the local one?

    Thanks!
    chris

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: forcing local port number from TcpSocket?


  3. #3
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: forcing local port number from TcpSocket?

    I saw that one, but the description didnt match what i needed, it seemed it was for something else.

    You can call this function in a subclass of QAbstractSocket to change the return value of the localPort() function after a connection has been established. This feature is commonly used by proxy connections for virtual connection settings.

    Note that this function does not bind the local port of the socket prior to a connection (e.g., QUdpSocket::bind()).
    How can this be useful if it does not bind the port until after the connection is established?
    Last edited by jacek; 3rd January 2008 at 17:24. Reason: changed [code] to [quote]

  4. #4
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: forcing local port number from TcpSocket?

    also on compile:

    /usr/local/Trolltech/Qt-4.3.1/include/QtNetwork/qabstractsocket.h:158: error: `void QAbstractSocket::setLocalPort(quint16)' is protected
    process.cpp:26: error: within this context
    make: *** [process.o] Error 1

  5. #5
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: forcing local port number from TcpSocket?

    Response from TrollTech...

    This is currently not possible using the Qt API, no.



    What you'd have to do if you really need to do this is to do the local

    binding of a socket descriptor yourself and then set the socket

    descriptor on the QTcpSocket afterwards using the setSocketDescriptor()

    function.



    We do plan to introduce this functionality at a later point though.

  6. #6
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: forcing local port number from TcpSocket?

    Just curious: why would you want to do it? The receiving end, i.e. the receiving TCP stack, does always know from which port the incoming connection originated. Otherwise it could not talk back.
    There are 10 people in the world. Those who understand binary and those who don't.

  7. #7
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: forcing local port number from TcpSocket?

    Some protocols define which port the sending system must connect from. Although this behavior has been deprecated in most protocols, it is still needed by some "antique" ones.

    A good example is the original LPD spec.

    The tool I am writing is an emulator that allows this setting to me configured... (i guess Ill have to not allow it for now)

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.