PDA

View Full Version : Disconnecting & connecting tcpsocket with proxy problem



altVis
5th April 2008, 10:44
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?

wysota
5th April 2008, 12:51
Can you show us some code?

altVis
5th April 2008, 13:05
socket->setProxy(getProxy());
socket->connectToHost(host,port);

// ...getting new server's ip...

socket->disconnectFromHost();
// socket->abort();
socket->connectToHost(newIp, port);
// <...From here :
//Server sends me http notification "connection established", then my app sends to server ACK and at once closing packet (FIN, ACK).

wysota
5th April 2008, 13:09
disconnectFromHost() is a non-blocking call. You have to wait until you get a disconnected signal before you reconnect to some other host.

altVis
5th April 2008, 13:18
And with abort() function same story?

wysota
5th April 2008, 13:24
same story.

altVis
5th April 2008, 13:44
I have tried to reconnect on disconnected() signal...and...same story.
Without proxy everything works fine.:(

altVis
5th April 2008, 17:39
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]

wysota
5th April 2008, 20:09
Maybe the proxy is somehow broken.

altVis
5th April 2008, 20:26
Well. Nope:(

wysota
5th April 2008, 20:40
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?

altVis
5th April 2008, 21:06
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.

wysota
5th April 2008, 22:39
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.

altVis
6th April 2008, 06:41
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 )

wysota
6th April 2008, 09:36
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?

altVis
6th April 2008, 10:06
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.



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.


Could you provide a minimal compilable example reproducing the problem?

Well. For now i have solved problem in a horrible way:



delete socket;
socket = new QTcpSocket(this);
socket->connectToHost(...) // new connection;


I'll try to write some code later.