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!