Results 1 to 5 of 5

Thread: connectToHost() resets local port number specified by bind

  1. #1
    Join Date
    Nov 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default connectToHost() resets local port number specified by bind

    hello!

    I try to connect to a server as tcp from client and bind(enter the port for the client), but after I connect to the host (used connecttoHost() method ) in the client
    the port changed.
    QT client:
    Qt Code:
    1. Socket->bind(QHostAddress("localhost"),2555);
    2.  
    3. Socket->connectToHost(QHostAddress::LocalHost,1458);
    To copy to clipboard, switch view to plain text mode 


    there is any method or approach to make the port for the client fix ??

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: connectToHost() resets local port number specified by bind

    The client always uses a dynamically chosen TCP port. Why would you want to fix it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: connectToHost() resets local port number specified by bind

    I'm implementing chat application and I want from client to be able to enter the port for him from textedit

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connectToHost() resets local port number specified by bind

    Why would a user want that? It is entirely irrelevant to the functionality they consume (chatting).

    Cheers,
    _

  5. #5
    Join Date
    Nov 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: connectToHost() resets local port number specified by bind

    You're right.
    However,I need the client enter port to bind UDP connect,but I used the tcp to send the online client.It was my error I tried used the same port for tcp_socket and udp_socket.
    thanks a lot!

Similar Threads

  1. QTcpServer or QUdpLocal, can't bind to IPv6 link-local
    By jyavenard in forum Qt Programming
    Replies: 0
    Last Post: 1st May 2012, 11:38
  2. QUdpSocket connectToHost and bind an the same port
    By aLiEnHeAd in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2010, 07:48
  3. serial port same local machine
    By adamatic in forum Qt Programming
    Replies: 7
    Last Post: 3rd February 2009, 07:29
  4. forcing local port number from TcpSocket?
    By nbkhwjm in forum Newbie
    Replies: 6
    Last Post: 8th January 2008, 18:28
  5. QUdpSocket bind / connectToHost ?
    By mnemonic_fx in forum Newbie
    Replies: 2
    Last Post: 17th July 2007, 03:20

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.