Results 1 to 5 of 5
- 11-26-2012, 07:11 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
[SOLVED]Multi-threading Problem with Console Input and Output
Hello everyone,
My question in a short (but maybe in a wrong access) form:
Is there any methode to get the characters of an UNFINISHED user input? "Unfinished" means the user has inputed something but has not pressed "Enter" key yet.
My question in a long and detailed form:
I want to implement a server program, that has threads for each connection. Each threads should report its state via a console output --- such as a new connection has been established; meanwhile the main thread should be able to control the connections via console input --- such as close a connection, or send some messages to an specified clients.
I tried console input and output in a "normal way", but if a "connection thread output" comes after the main thread shows the prompt of the control command, everything is messed up like this:
command> Connection reports goes here
reports goes here
and here
and here
_ <--- finally here is the cursor of new control command.
I've already tried "\b", before connection thread outputs any reports, output "\b"s back to the start of a line and then output the reports and finally append a "command> " after the reports. It also has problems. If the server user input something after the command prompt, but has not finished yet, while a new report from the connection thread comes. It looks like:
commConnection reports goes here
reports goes here
and here
and here
command> _
because I have outputed 9 "\b"s to overlap "command> "; however, if user has already typed something like "command> clos", then the last 9 chars will be overlaped, so "comm" remains.
Is there any way to solve the problem? Thanks a lot! And sorry for my English if I typed something wrong, because English is not my mother tongue.
racnilLast edited by racnil; 11-27-2012 at 11:08 AM. Reason: Solved problem
- 11-27-2012, 09:41 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Multi-threading Problem with Console Input and Output
Do you have multiple threads writing to the console?
Please do not ask for code as refusal often offends.
- 11-27-2012, 10:05 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: Multi-threading Problem with Console Input and Output
Last edited by racnil; 11-27-2012 at 10:08 AM.
- 11-27-2012, 10:45 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Multi-threading Problem with Console Input and Output
I would recommend not doing that.
If you need to display stuff coming in from one thing, while listening for use rinput on another, then this should probably be a Swing/JavaFX GUI, so you can have different components.Please do not ask for code as refusal often offends.
- 11-27-2012, 11:07 AM #5
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
standard input / output in console
By chipp in forum New To JavaReplies: 10Last Post: 05-11-2012, 07:45 PM -
Multi-Threading
By TonyDaniels in forum New To JavaReplies: 4Last Post: 03-09-2012, 06:16 PM -
Multi-Threading
By TonyDaniels in forum Advanced JavaReplies: 1Last Post: 03-09-2012, 05:52 PM -
multi-threading problem
By imorio in forum New To JavaReplies: 1Last Post: 04-25-2011, 06:52 PM -
Problem in Multi threading.
By Chetans in forum Advanced JavaReplies: 3Last Post: 03-23-2010, 04:42 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks