|
I guess that means server wouldn't know the connection has been broken when program ended abnormally without exec the close() api.
No. It means I didn't understand your question, and was asking for clarification.
I guess maybe my response should've been "it depends on how the socket was closed." Obviously you know what happens when the close() API closes the socket. What other possibilities are there?
a) You could use NETSTAT *CNN to close it. b) You could end the job (as David suggested) or end the subsystem, etc. c) The network cable could be cut. d) The power could go out. e) Some other hardware failure could occur.When the operating system knows that the connection is being terminated, and is able to react to it, it'll send a packet that contains the FIN ("finished") flag to the remote side. This tells the remote program that the connection is done.
That's what happens when you end the connection with the close() API, or NETSTAT, the ENDTCPCNN command, ending the job, etc.
However, when the network connection is cut, the hardware fails, the power goes out, etc, there's no way for the iSeries to send a response back telling the server that the connection has ended. In that case, the server program won't have any indication of the problem, and will just sit there and continue to wait for data.
Unless, of course, "keep-alives" are enabled on the TCP connection. When keep-alives are enabled, data is sent periodically to see if the connection is still alive. If no response is received to the keep-alive packet, the server would know that the connection has been dropped even if the problem is due to a network cable being cut. Since keep-alives aren't sent very often, this is usually only used for long-running sessions like TELNET.
For shorter sessions like FTP, SMTP, etc they usually just time the sockeet out if nothing is received for a given period of time. (maybe a minute or two) and disconnect it.
Well written programs should never assume that they'll receive a FIN packet. They should always have an alternate way of detecting that the connection is dropped... timeouts or keep-alives are reasonable solutions to the problem.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.