I\'m having a really hard time understanding why is this piece of code making my computer beep. I\'ve isolated this section of code to be the one producing the occasional beep,
Agree with the '\a'
beep explanation.
One more point about your code:
recvResult = recv(webSocket, buffer, BUFFER_LENGTH, 0);
buffer[recvResult] = '\0';
Note that recvResult
will be -1 if there's an I/O error (or if you're working in the non-blocking mode and no data to read so far).
In such a case you'll write into forbidden memory, which is (damn, how I hate this phrase) undefined behavior. Simply speaking - memory overwrite, which is bad.
You should check for socket error before writing into buffer