LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to tell if TCP closed because of RST or FIN?

I'm thinking it would be useful to log if the TCP connection ended "cleanly" or not. I saw this post and it seems possible in Python but I think in LabVIEW you'll get an error 66 either way. Anyone have an idea? possibly reading something from wsock32.dll?

0 Kudos
Message 1 of 5
(1,806 Views)

It's very unclear to me how you conclude that this is possible in Python from the link you post. I can't see Python mentioned anywhere in there.

That all said, relaying on such things on your side is the opposite of robust network programming. You do not want to do different code execution depending on if the remote side aborted or ordinarily closed the connection. In both cases you should simply assume that that connection has left your party and while it may return later on, it will do so through a new connection in either case. It will be however important for you to also explicitly close your side of the connection anyhow, such that the TCP FIN handshake can be completed. Otherwise the remote socket may stay lingering in the CLOSE_WAIT state forever. which could prevent you from reconnecting.

 

While I believe that you can indeed not really distinguish the two connection closures in LabVIEW, even if you could, there is a very big chance that this behavior might be rather platform specific. and might even change between OS versions and socket implementations. In general robust networking code is not about relaying on such minimal distinctions but rather about working with the more generic situation that a connection has been terminated by the peer, normally or not should not really concern your application.

 

Rolf Kalbermatter
My Blog
Message 2 of 5
(1,753 Views)

I dropped the wrong link. This is what I intended to link to:

https://stackoverflow.com/questions/53345265/detect-why-a-socket-closed-fin-vs-rst

 

I'm not planning on doing anything different in my application based on which way it disconnected. I just want to log it and aggregate the data as statistics across many installations. Theoretically, breaking down the data into more discrete categories might help reveal correlations that would not be otherwise apparent.

0 Kudos
Message 3 of 5
(1,749 Views)

Well, if I understand the TCP state machine correctly, the RST is really only meant to be sent if you try to establish a connection and the remote socket driver can't find an according socket bound to the specific port (or it is lingering in CLOSE_WAIT state). Once you have had successful data transmission between the two sides, the remote side is expected to terminate the connection through a FIN packet.

Of course there might be variations in how this in detail works out depending on the socket implementation, so while logging might possible reveal certain things, it might be actually more platform specific than anything else.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(1,743 Views)

I'm talking about the case where the socket has been established and is active. Yes, the remote side sends a FIN if the close is initiated at the application layer. But, if I reboot the remote side it sends a RST. I guess it doesn't care to watch the other half of the close in that case..

0 Kudos
Message 5 of 5
(1,725 Views)