Reputation: 8405
Note: I am primarily concerned with data validity and not authenticity, i.e I care if data becomes corrupt due to transmission error but care less about if a malicious user tries to alter and retransmit packets to the original intended party (something like a MITM attack).
I am recently building a network protocol based upon TCP (specifically using java's Socket
and ServerSocket
) and I ran into a little problem regarding how reliable data can be transferred from point A to point B using TCP.
My main concern right now is whether to include a SHA-2
hash on the payload (and possibly header) data of my custom packet structure. Through some research I've seen that TCP does have its own ECC but I've also heard its not particularly "strong".
Since java's Socket
is based off a TCP architecture, my questions are:
Does the Socket
class guarantee valid (non-corrupted/lost) data (at least to the certainty that I don't need to include my own data checksum)?
Does java itself (through whatever java code infrastructure) provide additional validation (over plain-old TCP) to data when its being sent over a TCP connection?
Upvotes: 2
Views: 437
Reputation: 328556
The TCP protocol contains checksums and retransmit machanisms to make sure your data doesn't get corrupted on the way. If a package is damaged (i.e. the checksum doesn't match on the receiving end), the TCP/IP stack will automatically ask the server to send this frame again.
There is no need to do anything at the Socket or Java application layer.
Upvotes: 2
Reputation: 310869
TCP does that. Nothing to do with the Socket class.
Java doesn't add anything to what TCP does.
Upvotes: 4