Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending ACK in socket C#

Tags:

c#

tcp

sockets

I need to send files to a server through Socket. The server will send ACK for every message i send. If i didn't receive the ACK within 30sec I'll have to send the request again.

My question is, how to send/receive the ACK? Is there any internal ACK or should the server send ACK in bytes? As per my understanding, the server here will not send ACK as message. So i want to know how to handle this ACK part.

Thanks in advance.

like image 581
VKh Avatar asked Apr 06 '11 14:04

VKh


1 Answers

This is probably a protocol that started life when used with serial ports. Which don't have the kind of delivery and error checking guarantee that's built into TCP. If the 'packet' you have to send has something like a CRC or checksum then that's a dead ringer for such a protocol.

Adding this kind of checking isn't necessary for TCP. It will probably work just fine when you simply blast the file and not pay any attention to the ACKs. Although you ought to read them to prevent the buffer from filling. A secondary way is to simply wait for something being sent back from that server before sending the next chunk of bytes.

If you want to check the ACK anyway then look for a single byte with the value 6, the default ASCII control code for an ACK. I wouldn't implement the 'resend when timeout' feature unless the protocol implements a 'block number' that helps it detect duplicate blocks, that's just likely to fail on the receiving end with double the data. Just send the next chunk.

like image 56
Hans Passant Avatar answered Oct 13 '22 09:10

Hans Passant