I’m currently working on a simple client/server file synchronization. For this, client and server follow a simple protocol which determines in which order messages are sent.
shortened protocol (Using Object/ByteArrayStreams):
Client loop:
- Send filename
- Send fileinfo
- Send data
- Wait for server confirmation
Server loop:
- Read filename
- Read fileinfo
- Receive data
- send confirmation to client
Repeat.
The problem is the protocol gets out of order when an error occurs during transmission and I usually get StreamCorruptedExceptions, since at least one side is expecting something else.
Here is a sample situation of the problem:
Server fails during file reception (3) for whatever reason. Now the server waits for a filename. Because of the error, the client arrives at part 3 sending the data. Then the the Exception is thrown since the server expects a message object and the client sends byte data.
What is the best way to solve this?
some thoughts
That way, the client can retry any stage, and the server will be able to respond accordingly.
Other thougt