Isaac Marino Bavaresco escreveu: > Dave Tweed escreveu: > = >> Vitaliy wrote: >> = >> = >>> Olin Lathrop wrote: >>> = >>> = >>>> ... you have to think carefully about what the receiving node might >>>> do if it receives two separate valid commands. A sequence number is >>>> the usual way around this, but there are other strategies. >>>> = >>>> = >>> - Avoid "vague" commands ("toggle") in favor of more specific ones >>> ("turn off") >>> = >>> = >> Specifically, look up the term "idempotent", especially as it applies to >> computer networks. >> >> -- Dave Tweed >> = >> = > > I use two sequence numbers, one for the packet and other for the command > itself. It is useful for networks with routing where the packets may > arrive out of order or multiple times due to routing problems. > > If the sequence number of the arriving packet if less or equal to the > last received one, just ignore it. If it is newer (inside a > predetermined window), check the command sequence number. If the command > sequence number is exactly equal to the last one, just resend the last > answer but don't execute anything. If the command sequence number is > newer (inside a window limit), execute it, send the answer and store the > answer. > > There must be provision for a synchronization packet which is not > sequenced itself. > > Regards, > > Isaac > = Forgot to comment the sender side behavior: When sending a new command, just pick the next packet sequence number and the next command sequence number. If didn't get response and need to resend the command, pick the next packet number but use the same command number. This way the receiver will never execute the same command more than once, even if the sender needs to resend it several times. After resending a command a predetermined number of times without success, assume an out-of-synch condition and enter a re-synching mode. If the sender only sends a command after receiving the answer for the previous, the commands will always be executed in the correct order, even with a lot of retransmissions and misrouted packets, although with some delay. Regards, Isaac __________________________________________________ Fa=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger = http://br.beta.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist