Results 1 to 4 of 4

Thread: QHttp - how close TCP connection

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default QHttp - how close TCP connection

    I have QHttp in threads

    When I run threads QHttp creates a connection, everthing is OK but after all in netstat I have open ports

    TCP 192.168.0.122:55770 fx-in-f113:http TIME_WAIT
    TCP 192.168.0.122:55771 fx-in-f100:http TIME_WAIT
    TCP 192.168.0.122:55772 fx-in-f101:http TIME_WAIT
    TCP 192.168.0.122:55773 fx-in-f102:http TIME_WAIT
    TCP 192.168.0.122:55774 fx-in-f113:http TIME_WAIT
    TCP 192.168.0.122:55775 fx-in-f100:http TIME_WAIT
    TCP 192.168.0.122:55776 fx-in-f101:http TIME_WAIT
    ....
    etc. (eq 100 or more open ports)


    how close it

    I tried use abort, close, clearpendintconnection etc like this:

    QIODevice *dev = http->currentDestinationDevice();
    if(dev){
    dev->close();
    }

    state for each qhttp connection changed from 5 to 6 (from Connected to Closing), but is not Unconnected

    how can I close Qhttp connection ater request?

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp - how close TCP connection

    The ports are closed - they are in TIME_WAIT. The rest is upto the OS.

  3. The following user says thank you to squidge for this useful post:

    juzwa (13th August 2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Re: QHttp - how close TCP connection

    Thank you for answer

    but i have another question

    I read that should set flag SO_REUSEADDR (WINDOWS) for socket, to reuse this ports which are in TIME_WAIT state

    example for set SO_REUSEADDR flag :

    Qt Code:
    1. int flag = 1;
    2. result = setsockopt( listensock, SOL_SOCKET, SO_REUSEADDR, ( char * ) &flag, sizeof (int ) );
    To copy to clipboard, switch view to plain text mode 

    but I can't set this option(flag) in QHttp class
    I tried found wher can I set this option in other classes QNetworkAccessManager, QTcpSocket, QNetworkReply but without success

    I only found info about SO_REUSEADDR flag in QUdpSocek class


    How can I reuse ports in TIME_WAIT state by using QHttp class

    (maybe I should use something other than QHttp, to reuse this ports?)

  5. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHttp - how close TCP connection

    I'd say SO_REUSEADDR is more practical/useful for server applications (which require to bind to specific ports) and you are doing client operations.

    Secondly, QHttp is obsolete and should not be used in new code. You really should use QNetworkAccessManager (but this will have the same restrictions)

Similar Threads

  1. QSqlDatabase Connection Close on Destruction
    By Sanuden in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2011, 15:32
  2. How to correctly close a database connection
    By anoraxis in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2011, 16:28
  3. Replies: 11
    Last Post: 20th January 2009, 14:10
  4. Qhttp get in qt3 to file? file is empty until app is close?
    By triperzonak in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2008, 15:54
  5. Setting a cookie for a Qhttp connection
    By Nyphel in forum Newbie
    Replies: 16
    Last Post: 5th April 2007, 15:30

Tags for this Thread

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.