Hello,
My question is simple. Since I am working on a small mutl-client server project, I want to be able to type information while the server is running and process what was sent locally. Like if I type in "connections" it will call on a function I already made that will display all clients connected.
Though, a slight problem is that I have that in my infinite server while loop. This is how my code works:Let me expound. My function processMessage() returns 1 if something generic was sent, and returns -1 if I request "disconnect" which will shut the server down. My read() command is supposed to make sure if something was read, then to process. But my other functions below that are supposed to look for incoming connections and read the data never get executed. It's almost like my read function waits for input, and doesn't move on.Code:while (1) { /* read local input stream */ if ((n = read(0, svrMsg, 63)) > 0) if (processMessage(svrMsg) == -1) break; /* look for incoming connections */ /* read data accordingly */ }
I have even attempted to flush the input stream:Though no luck. Is there another approach I should take?Code:while ((ch = getchar()) != '\n' && ch != EOF);
- Stack Overflow