with my first network programming , I have one problem.
After disconnecting and reconnecting the network cable, the client-
server connection cannot be reestablished.
The communication itself works fine. I create a “server
socket” with socket(), bind(), listen(). After accept()
the program waits with select() because a timeout is needed.
Incoming data from the client PC is read with recv(), sending
also works well.
Also working is the detection of the client closing the socket
and then reastablishing it.
The problem occurs after removing the network cable when a
connection is estabished: select() returns 0, just like a timeout
with no data present, so I dont see the connection is broken.
After reconnecting the cable the client can reconnect to my machine ,
but it cannot reconnect to my running server, no communication with
my server is possible.
Using “netstat -a” it looks to me, as if the client opens an additional
socket on my PC.
Output from “netstat -a” before cable is disconnected
(and also while cable remains disconnected):
Line 1: tcp 0 0 myhost.7001 192.168.178.245.1718 ESTABLISHED
Output from “netstat -a” after cable has been reconnected and client
Line 1: tcp 0 0 myhost.7001 192.168.178.245.1719 ESTABLISHED
Line 2: tcp 0 0 myhost.7001 192.168.178.245.1718 ESTABLISHED
I guess my server is somehow still waiting on “192.168.178.245.1718”,
while the reconnected client uses “192.168.178.245.1719”, (I don’t
know what 1718/1719 stands for.)
-Is this normal? I hope not…
-What could I do to detect the removed cable?
-Should I then close the socket?
-Is this broblem maybe fixed in newer versions?
An idea I have is to close the socket after some minutes it is not used,
and then reopen it. I don’t know if it would work, but I don’t like
that, maybe some data could be lost?
-TCP/IP SDK (4.25)
-Network card SMC EZ Card 10 from SMC, NE2000 compatible
I would be glad about any help, thanks in advance,