Results 1 to 16 of 16

Thread: Disconnecting & connecting tcpsocket with proxy problem

  1. #1
    Join Date
    Mar 2008
    Posts
    15

    Unhappy Disconnecting & connecting tcpsocket with proxy problem

    Hi!

    I don't know why, but i can't connect to another server after disconnecting from previous with same socket ( using proxy ).
    Server sends me http notification "connection established", then my app sends to server ACK and at once closing packet (FIN, ACK).

    Connecting with another (new one ) socket just fine, but not acceptable for my app.
    Looks like i must completely rewrite( or may be reset) socket.
    But how?

  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: Disconnecting & connecting tcpsocket with proxy problem

    Can you show us some code?

  3. #3
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    Qt Code:
    1. socket->setProxy(getProxy());
    2. socket->connectToHost(host,port);
    3.  
    4. // ...getting new server's ip...
    5.  
    6. socket->disconnectFromHost();
    7. // socket->abort();
    8. socket->connectToHost(newIp, port);
    9. // <...From here :
    10. //Server sends me http notification "connection established", then my app sends to server ACK and at once closing packet (FIN, ACK).
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: Disconnecting & connecting tcpsocket with proxy problem

    disconnectFromHost() is a non-blocking call. You have to wait until you get a disconnected signal before you reconnect to some other host.

  5. #5
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    And with abort() function same story?

  6. #6
    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: Disconnecting & connecting tcpsocket with proxy problem

    same story.

  7. #7
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    I have tried to reconnect on disconnected() signal...and...same story.
    Without proxy everything works fine.

  8. #8
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    Also i have tried to pause mine app ( from 10 to 60 sec) after disconnecting.
    Connection stream looks just fine:
    calling disconnectFromHost() function and than sleep for n secs.

    Application(A): [FIN,ACK]
    Server(S): [FIN,ACK]
    A: [ACK]

    ..pause..

    new connection
    A : [SYN]
    S : [SYN, ACK]
    A : [ACK] {http connection }
    S : [ACK] {connection established}
    A : [ACK]
    A : [FIN, ACK] { why??? error occurs only with proxy}
    S : [FIN, ACK]
    A : [ACK]

  9. #9
    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: Disconnecting & connecting tcpsocket with proxy problem

    Maybe the proxy is somehow broken.

  10. #10
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    Well. Nope

  11. #11
    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: Disconnecting & connecting tcpsocket with proxy problem

    How do you know that? It is the proxy that terminates the connection, right? Have you checked it using a network sniffer? Does a packet containing FIN+ACK actually originate from the proxy?

  12. #12
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    Yes FIN,ACK sending to proxy IP and going from proxy IP, connection binded to the newly assigned port.
    But first fin packet sends my app.

  13. #13
    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: Disconnecting & connecting tcpsocket with proxy problem

    Do the SYN numbers of consecutive packets match? Does the app raise the reset flag along fin and ack? What happens if you try to establish a connection once again with the same socket?

    By the way - I'd be surprised if the error originated in Qt, as Qt uses your system's mechanism of sending data through network, so it is the system that raises those flags. Qt can only request a connection to be closed. Maybe there is some error in Qt's socket state machine... hard to say, but I wouldn't blame it upfront.

  14. #14
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    1)Only fin,ack from my app and previous ack packet sequence and ack numbers equal.

    2)Uh, i haven't understood a question.
    fin,ack packet's rst flag is not set.
    Or you talk about Qt class qtcpsocket's some kind of reset flag?

    3) socket disconneting in the same way, but even after first syn|syn,ack|ack chain( i mean no http connection | http conenction established here )
    Last edited by altVis; 6th April 2008 at 06:47.

  15. #15
    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: Disconnecting & connecting tcpsocket with proxy problem

    Quote Originally Posted by altVis View Post
    1)Only fin,ack from my app and previous ack packet sequence and ack numbers equal.
    I don't mean "equal". Do they match according to the TCP protocol? Syn numbers have to match with ACK numbers and vice-versa.

    2)Uh, i haven't understood a question.
    fin,ack packet's rst flag is not set.
    Or you talk about Qt class qtcpsocket's some kind of reset flag?
    Yes, I mean the rst flag. If it's not set, the connection is not terminated but gracefully closed.

    3) socket disconneting in the same way, but even after first syn|syn,ack|ack chain( i mean no http connection | http conenction established here )
    Could you provide a minimal compilable example reproducing the problem?

  16. #16
    Join Date
    Mar 2008
    Posts
    15

    Default Re: Disconnecting & connecting tcpsocket with proxy problem

    Quote Originally Posted by wysota View Post
    I don't mean "equal". Do they match according to the TCP protocol? Syn numbers have to match with ACK numbers and vice-versa.
    Yes. Of course.

    Quote Originally Posted by wysota View Post
    Yes, I mean the rst flag. If it's not set, the connection is not terminated but gracefully closed.
    Yeap, i know. Same thing like with disconnectFromHost.

    Quote Originally Posted by wysota View Post
    Could you provide a minimal compilable example reproducing the problem?
    Well. For now i have solved problem in a horrible way:

    Qt Code:
    1. delete socket;
    2. socket = new QTcpSocket(this);
    3. socket->connectToHost(...) // new connection;
    To copy to clipboard, switch view to plain text mode 

    I'll try to write some code later.

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.