I am writing this chat program that uses ncurses as the interface. How am I suppose to simultaneously handle the socket file descriptors and user interation? My idea is below. The problem is now the loop only executes once for each button I press. How do I structure my program such that the sockets and user interaction are handled immediately once they are ready? I tried just having my poll include the file descriptors for standard input and output, but that does not work.
while(ch = getch()) {
poll sockets
loop sockets {
...
}
switch(ch) {
...
}
}
Also as a more general question. How does one typically write programs that handles user interaction and other things going on at once? It seems like there would be a standard way of doing this.
You can try
nodelay()on your input screen.But chances are you may want to go to threading down the line.