Reputation: 40193
I've a university assignment to create a server-client pair, where the client can transfer a file to server. Also there should be an integrity check to see if the file is not corrupt. I've implemented the actual file transfer, using the DigestInputStream
and DigestOutputStream
classes, that calculate the hash code of the file at transfer time. Now my problem is to send the hash calculated by the client to server, where the server must compare it to the hash calculated by server. I need an idea of some kind of protocol to send the actual file data, its hash code and file name. Thanks in advance.
Upvotes: 1
Views: 678
Reputation: 533492
You can use DataOutput/InputStream
DataOutput out = ...
String fileName = ...
byte[] bytes = ...
int hash = ...
out.writeUTF(fileName);
out.writeInt(bytes.length);
out.write(bytes);
out.writeInt(hash);
out.flush();
Upvotes: 0
Reputation: 3321
It is proabably easiest to implement using the Socket API.
Then you can take the following steps:
There are plenty of tutorials available on Socket and how to setup basic client-server communication.
Upvotes: 2