Reading and writing data to console?

Jul 12, 2010 at 9:46pm
Is it possible to read and write data to a console window at the same time? Also, if it is, can you give an example?
Jul 12, 2010 at 10:46pm
What? Can you explain better?
Jul 12, 2010 at 10:49pm
I don't get it either... What do you mean? What exactly do you want to do?
Jul 12, 2010 at 10:58pm
I'm trying to make a console chat program, and at the moment only one person can talk at a time. If there was a way to read and write to the console at the same time, either user would be able to send messages whenever they wanted, not just after the other person spoke. Does that clarify it?
Jul 12, 2010 at 11:12pm
No, but you can create the illusion via some simple multiplexing and some simple Windows Console Functions to position the cursor and update things in the right places
http://www.google.com/search?btnI=1&q=msdn+Console+Functions

Just keep checking whether there is input from your socket(s) and from the console, and instantly respond to each one as it occurs, then return to your loop. There are Windows wait functions to do just this, such as WaitForMultipleObjects():
http://www.google.com/search?btnI=1&q=msdn+WaitForMultipleObjects

Hope this helps.
Jul 12, 2010 at 11:13pm
You can use the curses library,
so you can get the input by character while the user is typing and move the whole thing down if a new message arrives
Jul 12, 2010 at 11:21pm
Ok, thanks! I'll look into it.
Topic archived. No new replies allowed.