LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Ncurses windows and sockets in asynch mode (?) (https://www.linuxquestions.org/questions/programming-9/ncurses-windows-and-sockets-in-asynch-mode-164998/)

krajzega 04-01-2004 11:22 AM

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?

Mara 04-01-2004 04:05 PM

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.

krajzega 04-01-2004 05:02 PM

I don't think that's good idea..because I won't put 2 applications in two different ncurses windows.

Mara 04-02-2004 02:17 PM

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.

krajzega 04-03-2004 01:31 PM

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.