On a UNIX machine using sockets I am sending commands to a server. This server responds with a (positive or negative) command. Therefore I now send the command and then read the response. But occasionally the server also sends out a command, to which my application has to respond.
What is the best logic to implement this loop? Always read, until I have to send something I guess. But how can I stop a read using sockets?
I use the system call read() and IO::Socket->print() to read from and write to the socket.