1

I am implementing a real time note sharing app using GKSession. Say 2 users - A and B are connected using GKSession.

Anything User A types is sent to user B (per character) and vice-versa.

I am using shouldChangeTextInRange from UITextViewDelegate and pass caret position, and the typed character along with other packet data. The character appears at the same position (caret position that was sent in the packet) in receivers' textview. Everything works except when both users send some character at the same caret position at the same time. How can I make sure both users' textviews are in sync with each other?

For example:

If user A sends character 'a' at caret position 2 and at the same user B had sent character 'b' at caret position 2 . What should the order be - 'ab' or 'ba' ?

I am using GKSendDataReliable and want to avoid packet received acknowledgement to be sent every time because other user will have to wait to send the next character which would kill all the fun.

New to stack overflow. Would really appreciate any suggestions on handling packet delivery and syncing data. Thanks a lot for your help guys!

Jos Vinke
  • 2,704
  • 3
  • 26
  • 45
heera88
  • 11
  • 1
  • 1
    Classical conflict situation; why not letting the users "win" in an alternate pattern. Start off with random user - suppose user A wins. Now user A wins and his character is used on both sides, next time user B wins? – Till Mar 18 '13 at 23:20
  • Thanks for your prompt response Jos! Doing it that way might confuse the users right? Say for example, I sent character 'a' and you sent character 'b'. If, by alternate picking, my character is used then in your textview 'b' should be replaced with 'a' to keep the data synced. But if you had sent 'b' and see 'a' printed on your screen - another conflict right there! – heera88 Mar 19 '13 at 00:26
  • There does not seem to be a solution for this problem that is not confusing - unless you simply tell both of your users that there was a conflict. – Till Mar 19 '13 at 00:37
  • Hmm...I think I'll have to research a little more. Thanks though Jos! – heera88 Mar 19 '13 at 04:38

0 Answers0