I’m trying to invoke receive()
on a TCP client to flush its receive buffer. However, it is just blocking indefinitely even though I’m providing a timeout. Here is a code snippet:
// query power status
debugLog("flushing socket...");
socket.receive({ timeout: 100 }); // to flush out anything in receive queue (but don't block if it's already empty)
debugLog("socket flushed, sending command...");
socket.send("op status ?\r");
debugLog("getting response...");
response = socket.receive({ timeout: 500 });
debugLog("parsing response...");
After the console log shows “flushing socket…” it just hangs and the timeout never seems to expire? Thoughts on what I may be doing wrong? In this particular instance, I know the buffer is actually empty, but that shouldn’t matter, should it? I’m invoking this in onConnect()
after I invoke connect()
.