Hello all. I have a question regarding TCPSockets. Lets say you connect and are issuing commands inside of the TCPSocket.Connect event. Lets say at that point in the middle of a block of commands within the TCPSockets.Connect event you lose network connectivity.How do I get TCPSocket to realize that we no longer have an “IsConnected”=True state when it still thinks we do. I understand TCP is layer 4 so the disconnect at layer 1 would be obvious however I would imagine TCP would be able to realize this loss of connectivity mid stream.
Any advise would be appreciated.
Thank you in advance.
You try & write something
It has no clue until you try to do something more and THEN you get the error
Maybe a Timer can be a useful assistance in this case?
To check if IsConnected still = TRUE?
The Error event should fire when a disconnect occurs.
[quote=55885:@Norman Palardy]You try & write something
It has no clue until you try to do something more and THEN you get the error[/quote]
I am watching this all in the IDE while stepping through the debugger. I turn off my MAC’s wireless network purposely right before a write. The “write” never changes the IsConnected=True unfortunately.
The LastError always stays at 0 during this test. If i run normally and disconnect normally I get a 102 as expected however during a mid stream disconnect I don’t get any errors.
I also tried a manual socket poll after the write directly in the connected event and I didn’t get any different results.
Also this is happening in a Console App in case that matters. Thanks again.
[quote=55929:@Jakob Krabbe]Maybe a Timer can be a useful assistance in this case?
To check if IsConnected still = TRUE?[/quote]
Thats kind of my problem. I can’t ever get IsConnected to go False Only when I pull the network plug in mid connection… Works fine if I attempt to connect to an unknown host (Error 103) as expected.
I think it is an OS problem and not a Xojo problem.
You can check the connection state of your socket with the “netstat” command.
Xojo TCP sockets are an abstraction of the underlying OS network stack.
Maurizio, I have just done that and you are right thank you. My OS is delaying in recognizing the down interface. I gave it more time in my IDE debugging and it finally showed my LastError 22. Phew
Weird. Again when I give it enough time in the debug I get Error 22 as expected now. However when I run my console app in the IDE it never fires the Error 22. Is the App going to fast through the writes or something do you think?
I think that console Apps depends on user applications support on handling events using DoEvents(): I don’t know how you are handling this aspect,
The OS network stack also has some timing involved in the error report part.
Maybe your application is writing when the OS has not yet recognized and reported the disconnected state of the socket.
It is a time thing. However is this normal? The OS shows “Inactive” on the link within seconds after I kill the interface. However it takes Xojo about 160 seconds later to catch the Error.
In this case the TCP protocol decides when the error can be intended as transient or permanent.
But this behaviour can vary from OS to OS i.e. not all networking stacks report error immediately in this specific case.