I am building a tutoring application that can be used to draw objects and then one is able to drag them around. I would like to know what is the best thing to do when someone clicks on an object and starts to drag it.

I was told I should "lock" it - prevent it from being grabbed by someone else at the same time and being able to drag it. But that would require sending a request to the server (and then to all other users connected to the tutoring session) to lock it which might take a bit of time (what if a teacher is in USA and student is in Africa on dialup)? I was also told I should loop until I see that the object was locked by me. This way, the user might not be able to grab and drag and object for several seconds (UX design problem).

I proposed perhaps to only enable one to drag object you drew, but that seems short sided. Any suggestions? Thank you!

  • Have you considered an 'all or nothing' approach? One person has control over all the items and can relinquish all control or not? Unless it is a requirement of the system that multiple people be able to modify it at the same time.
    – user40980
    Commented Jan 2, 2013 at 20:23
  • @MichaelT Unfortunately, there are no hard specifications. There is no customer, yet. The person in charge said he would like people to have control over all objects, but I can convince him of another strategy if the new one is better. Your solution would not allow users to interact with each other efficiently if they need to compare two objects or etc.
    – jn1kk
    Commented Jan 2, 2013 at 20:26

1 Answer 1


The way a lot of online real time games deal with latency is to go ahead and perform an action locally, then correct it later when the authoritative result is given by the central server. In your case, you start dragging the object locally, sending a lock request to the server as soon as your drag starts, but acting as though you already own the lock. If the lock request succeeds, you carry on as normal. If someone else beat you to it, the local client ends the drag and gives control of the drag to the winning user until the lock is released. None of the other users will see your aborted drag attempt.

You'll have to decide for yourself if having someone "steal" your drag on rare occasions is more annoying or less than having to wait for a lock every single time. In my opinion, removing the delay in the most common case is the preferred solution.

  • But it seems we need some kind of queue then? What if the lock doesn't get to the server until after I let go? And then the unlock signal gets processed faster than the lock signal? Then the lock signal will get processed and lock if forever (unless I check if the lock is already owned by me).
    – jn1kk
    Commented Jan 2, 2013 at 22:02
  • Yes, you need some way to guarantee the order of packets. Commented Jan 2, 2013 at 22:16
  • Jeez, this might be worth more trouble than it is worth.
    – jn1kk
    Commented Jan 2, 2013 at 22:26
  • 2
    You could also do the dragging entirely locally, only sending a message to the server for the 'drop' part. Obviously, this means that other users won't see your dragging, and if two people drag the same object at the same time, whoever drops second wins, but I can very well imagine this to be acceptable.
    – tdammers
    Commented Jan 3, 2013 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.