c - Regarding implementing a new transport protocol -
i trying implement own transport layer protocol tcp used application, on top of network layer using raw sockets api in linux. working on ubuntu 14.04.
i have been able send , receive packets.
now in part of implementing transport protocol, looking forward write functions
connect(int sockfd) - establish connection server.
send_data(int sockfd, char* data) - send data
receive_data(int sockfd, char* data) - receive data
close(int sockfd) - close connection
also since trying implement protocol tcp, keep protocol reliable want send acknowledgement each received data packet. have made own tcp header follows
typedef struct rtlp_hdr { int checksum; short int src_port; //defined short int des_port; //defined int seq_no; int ack_no; }rtlp_hdr;
now in implementation of send_data function after send data packet wait receive acknowledgement next data packet given time, , if don't receive ack or receive corrupted ack( after checking checksum) resend data. facing problems in creating corresponding receive_data function same, how know ack sent received data has been delivered sender, since there no ack ack.
if has ideas can or if going in wrong direction please correct me. in advance.
i have written code connect(int sockfd) using 3-way handshaking working fine, can share that.
as mentioned, there no way guarantee message arrives @ destination. if understand question right hope simple example below can you.
you have client a, , server b. client sends packet named a1 b. b saves name of last received packet, , replies ack.
if ack makes client sends next packet, named a2.
if, however, ack lost, client resends data named a1 after while. when server receives a1 second time (using saved name), can assume ack lost. server resends ack, hoping make client time. continues many times neccessary.
as see, server not need know if ack has been delivered client. receiving of duplicate packet tells server ack lost. (ignoring spurious timeouts simplicity)
Comments
Post a Comment