Trying to program a stop and wait network protocol in C which will send a packet in the form of a struct
Code:
struct MyHdr{
unsigned char seq; //sequence number
unsigned char wndwsize; //size of the send window
unsigned char pcktsize; //packet size
data char[sizeof pcktsize]; //data array size of packetsize (-overhead)
};
I have been reading up on the send() and recv() classes but still don't have enough knowledge to know how to send a "packet" over. Can someone clarify how to do this with me?
Here's what I have been playing with
Code:
while(fread(buffer,1,64,in) !=0){
struct MyHdr packet;
resent =0;
count++;
packet.pcktsize = buffer;//copy buffer into our packet 64bytes
packet.seq = count;
packet.wndwsize = count;
do
{
//something with a CRC
//
}
send(sockfd,packet);
}
Can I just send with the given socket and the packet? Also how would I receive it?