Ncurses windows and sockets in asynch mode (?)
I would like to write something looking like irssi or bitchx using ncurses. I've prepared a few windows and the problem appears when I want to use window input and a loop, let's see (it's not full code , only a schema) :
fcntl(socket, ....); //sets a socket asynchronous mode while(1) { wgetstr(window, buffer) //it get's some data from user in one window send(...); //sends input data to a socket recv (....); //receives data from a socket printf(received data); //prints this data to ther window } It's a bit stupid, because this application should still receive data from socket and in the same time from user. But it waait until user put some data and then receives something and print. It should look as a two different loops which are running in the same time. Any ideas? |
You can make your program use two threads (one dealing with socket and the second one with user) or use 'select' to wait for first event.
|
I don't think that's good idea..because I won't put 2 applications in two different ncurses windows.
|
Threads are in one program, they can write to the same window and so on (but synchronization is needed). So probably 'select' would be better for you. It allows you to wait at the same for socket and user input.
|
It isnt also good idea, because:
wgetstr(...) means the same as: while(char!='\n') { getch(char); add-char-to-buffer; } |
All times are GMT -5. The time now is 03:30 PM. |