I’m having a problem doing network programming. I’m using the TCP protocol to communicate between server and client. My code is working, but I as yet can’t detect that the data is successfully sent or if it failed. I have the following questions:
- How does one check that the bytes have been sent with socket TCP successfully or not?
- How acknowledgment (ACK) is work in TCP protocoll ?
- How does one do secure communication using socket programing?
You can explain in C#, Java or PHP.
An explanation of how TCP/IP works is best left as a research exercise, rather than an ad hoc SO question. While the usual first stop might be Wikipedia, that probably doesn’t give you a good introduction from a conceptual level. In the comments there is also a link to a TCP tutorial.
However in essence, TCP is, as the name says, a transmission control protocol that provides a mechanism for the reliable delivery of a byte stream. Given a stream of bytes, TCP basically ensures that the receiver receives the bytes in the correct order. If a byte in the middle of a stream got “lost”, then TCP can detect this and will arrange its re-transmission. All of this is transparent to the receiving party. The magic of TCP is that the receiving party just reads from the socket, and the data appears intact and in the correct order.
When you utilise a TCP socket, you don’t deal with ACKs and NACKs and retransmissions. All of that is transparent to your application.
Now, you can detect that the other end has gone away, but you can’t know that the other end definitely did or did not receive your message. This is the Two General’s Problem.
But really, if you’re interested in how TCP works read W Richard Stevens’ TCP/IP Illustrated. Not trying to palm you off, but to understand it, you really do need to go away and read about it (either online or on dead trees).