Using TCP Sockets (C#), How do I detect if a message got interrupted in transit, on the receiver's end? -
im writing server application iphone app. section of server im working on relay server. relays messages between iphones, through server, using tcp sockets. server reads length of header stream, reads number of bytes stream. deserializes header, , checks see if message relayed on iphone (rather being processed on server).
if has relayed, begins reading bytes sender's socket, 1024 bytes @ time. after each 1024 bytes received, adds bytes (as "packet" of bytes) outgoing message queue, processed in order.
this fine, however, happens if sender gets interrupted, hasn't sent bytes (say, out of 3,000 bytes had send, sending iphone goes tunnel after 2,500 bytes)?
this means other devices waiting on remaining 500 bytes, dont relayed them. if sender (or else matter) sends data these sockets, think start of new message end of last one, corrupting data.
obviously description above, im using message framing, think im missing something. can see, message framing seems allow receiver know exact amount of bytes read socket, before assembling them object. wont things start hairy once byte or 2 goes astray @ point, throwing out of sync? there standard way of getting in sync again?
wont things start hairy once byte or 2 goes astray @ point, throwing out of sync? there standard way of getting in sync again?
tcp/ip ensures no bytes go "missing" on single socket connection.
things bit more complex in situation, (if understand correctly) you're using server sort of multiplexer.
in case, here's options off top of head:
- have server buffer entire message point before sending point b.
- close b-side sockets if abnormal close detected side.
- change receiving side of protocol b-side client can detect , recover partial a-stream without killing , re-establishing socket. e.g., if server gave unique id each incoming a-stream, b client able detect if different stream starts. or have additional length prefix, b client knows both entire length expect , length individual message.
which option choose depends on kind of data you're transferring , how easy different parts change.
regardless of solution, sure include detection of half-open connections.
Comments
Post a Comment