When I send msg to a WebSocket client is it blocking or non blocking code ?
ws.send(msg);
In other words, is it a good practice to wrap a send within a setTimeout ?
I am using the Node Einaros WS library but I think this question applies to many other libraries such as Socket.Io or Engine.Io too.
Firstly, to wrap a blocking function within a setTimeout is only going to delay the blocking call, right? So it wouldn't matter if you did that or not. The non-blocking nature of node comes from the fact that the underlying engine runs an event system to let you know when traditional blocking calls (such as file system retrieval) are complete.
Websockets are a "fire and forget" protocol, which I think is what you're trying to ask. The server and client do not wait for a response and instead use the same system as I mentioned above. They will 'listen' to events when they are emitted from the other side and then deal with a process. It is worth noting that websocket communication in the browser do so only under the TCP protocol, meaning if a packet is lost then it will request it again from the server. This is not usually a problem, but in a realtime game sense where milliseconds are important, this is not usually ideal.