javatcpftpnetwork-protocolsapplication-layer

How to access information about network from TCP?


I am writing an application layer protocol in Java. It basically just transfers files. I would like it generate error messages if the transfer is unable to be completed or if the connection between the client and the server is interrupted.

Is there a way to get the information about the connection or status of the transfer from TCP? Or do I need to rely on what I'm working with at the application layer? If I can access information from TCP, how?


Solution

  • TCP is not aware of the "status" of a transfer. That is an application protocol concern, not a transport layer concern.

    As for the status of the TCP connection, there is no way to inquire directly. Instead, you find out the status when you attempt to read or write data. The outcome of the read(...) or `write(...) to gives some information about the connection status..


    Unfortunately, this means that providing clear and accurate information to your application's user about why a transfer has failed is difficult. But this is inherent to network connections. The real problem is that simple / clear diagnostic information is not directly available anywhere.