I am trying to implement a simple protocol by reading messages coming from a server and send messages back accordingly. I basically have a while-loop that at the moment looks like this
while(recv(sock, buffer, BUF) > 0 /* more stuff */) {
/* Handle message */
}
However, this gives me the whole message sent by the server until it's finished or the length specified by BUF is reached.
It would be much easier to be able to read it line-by-line and not like this, since sometimes the server sends several lines at once. Of course it is easy to implement a function that splits up a string in its lines, but I rather want a function that I can replace the recv(...) with that gives me all the lines. How can I realize something like that?