Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Trying To Make A Shared JTextArea  (Read 1795 times)
0 Members and 1 Guest are viewing this topic.
Offline Ignasis

Senior Newbie





« Posted 2012-12-30 19:45:58 »

Hey There Everyone,

Sorry if this is in the wrong place, really isn't necessarily for game development sooooo just didn't think another spot was really relevant.

I'm trying to make a JTextArea that can be accessed by two or more people on different computers, two for now, and edited simultaneously. It's actually an interesting problem, although perhaps just for me since I've only been coding for 3-4 months, all of which in Java. The issue is preserving both people's inputted text. The analogy I use is that if two people simultaneously edited a wikipedia page, ultimately the last person to click confirm would be the one whose information would be shown at the end of the day, which cannot happen in this case. Text needs to be sent constantly between all clients, but what is inputted needs to be preserved. This is probably a far bigger project that I am imagining, and right now I think it's pretty big, but it seems like fun so, any thoughts on how I could be addressing this issue? If you need a more in depth explanation or some code, feel free to ask.

Ignasis
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #1 - Posted 2012-12-30 19:50:40 »

You could synchronize your two users using a database. Not sure how scalable that would be. Another alternative would be to have a server program that communicates with the clients and has a central copy of the edited document and uses it to keep the clients synchronized.

Hope I could help,
h3ckboy
Offline Ignasis

Senior Newbie





« Reply #2 - Posted 2012-12-30 21:14:13 »

You could synchronize your two users using a database. Not sure how scalable that would be. Another alternative would be to have a server program that communicates with the clients and has a central copy of the edited document and uses it to keep the clients synchronized.

Hope I could help,
h3ckboy

I thought about that a while ago, couldn't get it to work; however, when you mentioned this I had an idea. But i ran into the same problem that I am currently having and that I had previously. The issue is that while the server would have that central JTextArea, it isn't the JTextArea being edited by the clients, so the problem then becomes synchronizing what the clients input, which is the issue I've been having for the last couple days or so, since I started to tackle this problem again
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Varkas
« Reply #3 - Posted 2012-12-30 21:19:34 »

You can do it in a distributed manner too. But each client has to broadcast it's changes to every other client then.

The idea is to get all changes into the same sequence, then all documents will stay in sync.

In the "distributed operating systems" lessons we learned an algorithm to do just that, but I must admit, I have forgotten the name and google wasn't helpful - 15 years can be a long time. I just know that such algorithms exist. Maybe someone with more recent computer science knowledge can help there - it's an algorithm to synchronize virtual clocks in distributed systems, and as a side effects it also allows to keep events (e.g. user input from different users) in the same sequence on all nodes of the system.


if (error) throw new Brick(); // Blog (german): http://gedankenweber.wordpress.com
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #4 - Posted 2012-12-30 21:20:42 »

I think you're looking at this backwards. You aren't synchronizing the JTextField, you are synchronizing the String for the contents of the field, and as a consequence the JTextField.

Does that make sense?
Offline Ignasis

Senior Newbie





« Reply #5 - Posted 2012-12-30 21:49:00 »

I think you're looking at this backwards. You aren't synchronizing the JTextField, you are synchronizing the String for the contents of the field, and as a consequence the JTextField.

Does that make sense?

Yep it does, that was what I was trying to do. I thought that was what you meant though, synchronizing the TextArea. Meh, was worth a try anyways, I think at the end of this, after I've tried just about everything else, I'm gonna have to do what I was hoping I wouldn't. Make a really really complicated comparison method of all the strings I would get from a getText() method, but it'll probably get simpler the shorter the interval is between comparisons.
Offline Danny02
« Reply #6 - Posted 2012-12-30 22:17:16 »

I don't know if it is possible with the standard swing controlls, but the best way to do it would be to do it like a realtime game, send the command for each keypress over the wire.

Like cursor position at char 57, add 'a'. Then one could do some locking, like lock a line for other users to not have to deal with sync problems
Offline Ignasis

Senior Newbie





« Reply #7 - Posted 2012-12-30 22:22:18 »

I don't know if it is possible with the standard swing controlls, but the best way to do it would be to do it like a realtime game, send the command for each keypress over the wire.

Like cursor position at char 57, add 'a'. Then one could do some locking, like lock a line for other users to not have to deal with sync problems

Um what method would get me cursor position? I wanted to look that up before, and I suppose I could look it up, but I have more to say so I may as well just ask the question. Also, locking kind of defeats the purpose I think. Because then well, the concept of simultaneous goes out the window. I want the simultaneous, just a pain to program the simultaneous lol... (That probably sounded really dumb) that's what I'm currently struggling with, although right now I'm adding features to the GUI and other small things before running some tests.
Offline Danny02
« Reply #8 - Posted 2012-12-30 22:30:27 »

do you really want to edit the same word or the same sentence  at the same time?
Offline Ignasis

Senior Newbie





« Reply #9 - Posted 2012-12-30 22:32:07 »

do you really want to edit the same word or the same sentence  at the same time?

The idea is to be able to write at different places in the page, at the same time. And how much do I want to do it? not really sure...
I just think it would be interesting to make.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #10 - Posted 2012-12-30 22:41:15 »

Interesting problem.
The main problem would be to mix multiple user input at once.
I guess you need to have some sort of index for each word in the document.
Then, when it receives user input like: "xxx typed the characters 'en' after word 56", this way the result wont get garbage when it needs to update.
However this method is maybe a little to easy, you may need to think about an much safer system.
Offline Ignasis

Senior Newbie





« Reply #11 - Posted 2012-12-30 22:58:03 »

Interesting problem.
The main problem would be to mix multiple user input at once.
I guess you need to have some sort of index for each word in the document.
Then, when it receives user input like: "xxx typed the characters 'en' after word 56", this way the result wont get garbage when it needs to update.
However this method is maybe a little to easy, you may need to think about an much safer system.

Lol, someone that understands that this is somewhat interesting Smiley
I was thinking of comparing the text in the textareas when keys are typed or something, but you raise a good idea, Wouldn't need any kind of index, would simply have to take cursor location and treat all text in the textarea as one long string (I've already verified this to be the case), and then substring where up until where the cursor is and then concatenate the input and then concatenate the substring whose index is the cursor location + 1, assuming this updates after every keypressed. My concern is that okay I update, and then what happens is someone elses update comes after this update but before they have received the update, as such, the cursor location is inaccurate. Gonna have to ponder this.

EDIT:

Gonna call it quits on this for today, been working on it 2-3 hours, giving the Client GUIs more functions and stuff, now my brain hurts.
Will read thread progressively through the day though.
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #12 - Posted 2012-12-31 09:02:38 »

My concern is that okay I update, and then what happens is someone elses update comes after this update but before they have received the update, as such, the cursor location is inaccurate.

Thats why i was talking about some sort of index, these indexes are unaffected by user input, so it wont matter when the text moves.
Offline Ignasis

Senior Newbie





« Reply #13 - Posted 2012-12-31 22:16:05 »

Seems to have some sense to it, I'd have to think more about it. But what happens if you want to delete a word?
Offline BoBear2681

JGO Coder


Medals: 18



« Reply #14 - Posted 2012-12-31 23:40:43 »

To do this the "right" way, you'll want to learn about the JTextComponent design - Documents, etc first.  Read through this, particularly from the "Concepts: About Documents" section down.

One other major consideration is that you should take care to not block the EDT with network calls whenever possible.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Grunnt (16 views)
2014-09-24 03:38:19

radar3301 (14 views)
2014-09-22 12:33:17

BurntPizza (31 views)
2014-09-21 15:42:18

BurntPizza (22 views)
2014-09-21 14:30:30

moogie (20 views)
2014-09-21 13:26:15

UprightPath (29 views)
2014-09-21 09:14:06

BurntPizza (33 views)
2014-09-19 16:14:18

Dwinin (48 views)
2014-09-12 22:08:26

Norakomi (75 views)
2014-09-11 02:57:51

TehJavaDev (105 views)
2014-09-10 19:39:09
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!