I have three applications that talk to each other using sockets. They can all live on their own machines but they can also share a machine. Right now I'm having two of them on the same and the third on its own machine. I'm trying to make my communication bullet proof so I unplug cables and kill the applications to make sure everything works as intended.
Here's a quick sketch of the thing:
Now, when I unplug the network cable to PC2 (the red connection "Con B"), the internal connection stops talking (the blue connection "Con A"). I send stuff from "App 1" on the socket that never gets to "App 2".
I have made a mechanism that discovers this and disconnects and then reconnects and after that I can unplug the cable all I want and "Con A" just keeps working. It's only that first time.
I have confirmed having communication through "Con A" before disconnecting "Con B".
I connect and reconnect exactly the same way, it's the same code, so there's no difference.
What's happening?
Additional information trigged by answers:
PC 1 and PC 2 share addresses down to the last byte.
I have an internal keep alive mechanism, I send a message and expect a response every 10 seconds.
When I kill App 3, this does not happen, only when unplugging the cable.
When you unplug/replug the Ethernet cable, what happens is that your network adapter is disabled/reenabled.
It won't damage your computer nor will it damage any hardware, though its a good habit to remove all external cables when your PC is switched off. P.S. I personally never unplug any external item be it a mouse or a keyboard or even the external cooler from my laptop, Lan is always plugged in.
Some users may experience a Network Cable Unplugged error. This error indicates that the computer does not detect power moving through the Ethernet cable. The network cable is either faulty or is not connected correctly.
What address are you using for "Con A"? If you are using an address that is bound to the external network adapter, even though you're talking to the same machine, then what you describe could happen.
What you can do is use the address localhost
(127.0.0.1) for "Con A", which should be completely independent of what happens on the external network.
On some platforms (windows) pulling the network cable tells the network stack to activly invalidate open socket connections associated with the interface.
In this scenario pulling a network cable is actually a bad test because it provides positive feedback to your application that it may not receive in a real life situation.
One common error for people to make when writing client/server applications is to not incporporate an application layer keep-alive or at least enable keepalives at the transport layer. An application recv()ing data can otherwise be forever oblivious to any failure condition until it write()s and the write fails due to transport layer timeout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With