• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Error detection in Client Server Communication

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All!
I have a client-server application in which I send packets from the server to the client in compressed form. From the server, I first send the size of the compressed bytes (the data size), followed by the actual compressed bytes (the data).
At the client end, I first read the size of the compressed bytes and then read in that many bytes from the socket. This is done for every packet sent by the server. There is no delimiter between any two packets.
Now, I have a doubt that since I am dependent on the data size, if somehow the data size for one packet becomes erroneous, then all subsequent packets will become erroneous as well. Let us consider the following scenario:-
1. Packet1: Length ---> 20 (sent as 2 bytes)
Data -----> The first 20 bytes available
2. Packet2: Length ---> 25 (sent as 2 bytes)
Data -----> The next 25 bytes available
Now, if somehow the client gets the length of packet1 as 21 instead of 20. Thus, what will happen now is that the client will get the first 20 bytes of the data of packet1 plus 1 byte (the MSB) from the length of packet2. Thus, in this case, not only has packet1 become corrupt, but so has packet2 since the length of packet2 has now become 5 instead of 25. As a result, all packets after packet2 will also become corrupt in this way.
Can there be some way such that even if the length of any 1 packet is received incorrectly, only that packet will be affected and no other?
Waiting for a reply from all you learned people out there....
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a checksum on each packet either at the end or the beginning. After you read the packet recalcute the checksum on the client and compare the two for integrity. If they don't match request that the packet be resent. This scenario may require some modification of both client and server but should not be very difficult to implement.
 
reply
    Bookmark Topic Watch Topic
  • New Topic