Answer the question
In order to leave comments, you need to log in
Do I need to validate received data and send notification of receipt when using TCP?
Hello!
I am writing a program for exchanging files in C# using the TCP protocol and sockets. I know that this protocol provides reliable and ordered data delivery. But is it possible to rely on it completely, in terms of the fact that the received data does not contain errors that occurred during transmission? Here is a quote from the wiki:
Although the protocol performs a checksum check on each segment, the algorithm used is considered weak. (...) In general, distributed network applications are encouraged to use additional software to ensure the integrity of the transmitted information.
public async Task ReceiveAsync()
{
await header.ReceiveAsync(netHelper); //Получаю заголовок.
if (header.LengthData != -1)
buffer = await netHelper.ReceiveAsync(header.LengthData); //Если в сообщении есть данные, то получаю их.
}
public async Task ReceiveAsync()
{
const byte SUCCESS = 1;
const byte FAILURE = 2;
if (await header.ReceiveAsync(netHelper))
await netHelper.SendAsync(new byte[1] { SUCCESS });
else
await netHelper.SendAsync(new byte[1] { FAILURE });
if (header.LengthData != -1)
{
buffer = await netHelper.ReceiveAsync(header.LengthData);
if (CheckHash(buffer, header.Hash))
await netHelper.SendAsync(new byte[1] { SUCCESS });
else
await netHelper.SendAsync(new byte[1] { FAILURE });
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question