0

Ok, I have been researching how to do this over the past few days and I haven't really come any closer to finding a solution or example. Basically, I have a server/client system set up so that I can send and receive text between two Java applications. I just can't figure out how to go about keeping the text in sync with each other. (Something like Google Docs)

If anyone can point me in the right direction or show/link me an example it would be much appreciated.

Thanks in advance.

4

1 回答 1

0

The brute force way would be to just send the entire text blob whenever it's updated, and let the other side sync up to it.

There are two main problems with this approach:

  1. If the text blob is really really big then there's redundant data being sent back and forth
  2. 如果双方同时进行许多更改,尤其是在编辑文本的完全相同区域时,可能会出现合并问题

第二个问题可以通过某种确认回复来缓解,这样您就可以知道更新的 blob 是否在另一侧被“接受”。这样,双方可以就数据的有效状态保持“一致”。但是,如果双方都不会承认对方的变化(无论出于何种原因),这仍然可能会失败。

我能想到的唯一其他一般想法是利用一些版本控制系统使用的库,如 SVN 或 GIT。这些可能具有很好的差异和合并功能,可以使更新更容易。仅发送差异也可以缓解上述问题 #1。

于 2013-03-30T10:31:13.247 回答