PDA

View Full Version : QTcpSocket stays in ConnectingState after reconnection



rybka007
18th September 2013, 13:21
I have a problem with QTcpSocket. I use it to connect with hardware through ethernet port. Everything works ok, I even created a timer, which fires every 2s to check, whether connection is still alive. When i plug out the Ethernet cable, my program shows information about lost connection. Then when I plug cable again, Qt won't allow me to connect again for some time (5-10 minutes). It finds hosts and stays in connecting state. This happend even when I restart the application - it does not help. The same problem does not exist i software provided by hardware manufacturer. Could you tell mi what is wrong?

wysota
18th September 2013, 13:46
You're not setting a SO_REUSEADDR flag on the socket and the hardware manufacturer probably does. Qt has nothing to do with this, it is your operating system that prevents a quick connection on a port that recently has not been closed gracefully.

rybka007
18th September 2013, 13:50
Ok, where can I do this? I've compiled the program both on Ubuntu and Windows, the result is the same. But the manufacturer's software manages to reconnect succefully, even though I am blocked.

wysota
18th September 2013, 15:03
man setsockopt

anda_skoa
19th September 2013, 09:07
Hmm, I have to say I am also quite puzzled by this.
I have done tons of network programming with Qt and I've never seen this happen.

Especially not on unrelated sockets. And restarting the application is as unrelated as it gets

What happens if you try to connect with telnet after the connection has been lost and cable has been reconnected?
Can it connect successfully?

Cheers,
_