2

I'm trying to make my program robust against network disconnections. Right now, if I disable ethernet network from OS (I'm over Ubuntu 11.10, but I guess that should not matter), my sockets recover once the network is enabled again and everything goes all right.

Since now I have supposed this test was the same as unpluging the ethernet cable. But it is not, since my program is suddenly terminating when doing this.

I want to know what's the difference between these two scenarios, and how to detect both of them. I'm using QTcpSockets from Qt and C++.

Also, when wifi is no longer detected, I guess it's equal to unplugging ethernet cable, while disabling it at the OS is equivalent to disable ethernet network. Am I right?

Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
  • Please show us how you handle disconnections so far (even pseudo code would be great). – user703016 May 25 '12 at 08:42
  • In general, if you have a client and get an error (no matter what) you should try to reconnect. – Some programmer dude May 25 '12 at 08:46
  • Sure, I try to reconnect with each error I get. If my program crashes, it must be due to some variable set to null I'm trying to access. But what I want to know is what's the difference between those two scenarios – Roman Rdgz May 25 '12 at 09:15
  • Consider third scenario. You're connected to router, so basicly your "link" is always working BUT your router losts connection with internet. Your OS still thinks that you're "connected" as your ethernet link still works fine. – Kamil Klimek May 25 '12 at 09:19
  • That third scenario is not a problem for me, because I'm just stablishing a local network, no need for internet in this project. In a different application, that scenario would have to be considered too, of course. Anyway I can see a clear difference between this one and the other two, which are more confusing to me – Roman Rdgz May 25 '12 at 09:21
  • Have you tried running your program in a debugger? – Some programmer dude May 25 '12 at 09:44
  • Well, then consider that remote in your local network gets disconnected. Same situation as "internet link" get lost. Remember that there may be plenty of devices between you and remote. Each link can get down and your link can still be up – Kamil Klimek May 25 '12 at 09:48
  • You will never know or detect if Ethernet cable is unplugged or am I wrong? How are you testing if your socket connection is still alive? For me, when I unplug cable disconnect signal randomly emits, usually time taken for OS to recognize this is also huge. – krizajb Oct 16 '12 at 13:23

1 Answers1

0

When the driver is enables, it means there is a program running at the OS kennel that manages different scenarios. For example, on cable disconnect, there is a link drop. And entering to low power mode. When disabling the driver either there is a firmware on your device that could manage the device on, or there device will be off.