Hi, as part of my project, i need to write code that actually implements the tcp layer functions. Could anyone tell me where i could get some idea on how to code the functions of tcp layer (i.e. I need to manage the transfer of data between the network and app layer)
This is a non-trivial task. There are many questions that you've left unanswered to help us help you.
As an assignment, is this part of some larger context system you must fit into? For instance, is there an API for communicating with your upper and lower layers? Are you using a Linux-based stack? Windows?
What version of TCP do you wish to implement? Will this be stripped (with fixed options) or will you implement all options?
The TCP version(s) used by Linux are actually pretty modular. If you are looking to use that model have you been given a design? Will you simplify and only implement a single version not intended to fit a particular model? If so, this loops to my first question.
In addition to all of that; what is you experience level? What have you tried so far?
It is a part of a larger system. The API for communication is already defined. Am using Linux. I would like ti implement a simple version of TCP that just handles data transfer and re-transmissions on timeout.
I am a beginner. Given a client and server.. My code transfers the file name correctly from the client to the server but i have trouble transferring the file contents back from server to client.
TCP generally works by maintaining a window of sent bytes in the stream and adjusts that window based on ACK/NACK from the remote end. The timeout can be implemented several ways each with trade-offs but really depends on the system you are developing to. In general, though, the timeout works by setting a timeout on each chunk of data you send, as each of those chunks get ACKed you drop the timer. This way, if some chunk is not acked in a particular amount of time the timer will fire and a retransmission will occur. There really is a wide arena for implementation here. There are variations on just about every aspect of the TCP algorithm for one reason or another.
My suggestion is that you start with a fixed timeout (instead of basing it in RTT) and have a single timer for each chunk of data you send. If you've got the communication between layers working (which it sounds like you do) then this will be the shortest path to a working TCP. You can extend as necessary once you have that.
I wouldn't even worry about the back-off mechanism until you have all of the previous pieces in place and tested.