I've got a PHP WebSocket server that sends multiple messages back to the client, with a delay between each message. To test it's sending a message, sleeping for a couple of seconds, sending another message; rinse repeat a few times. I can watch what the server is sending and it's sending out a message every 2 seconds like it should be.
My JS looks like this.
var ws = new WebSocket('ws://example.com:1234');
ws.addEventListener('message', function(msg) {
console.info(msg);
});
I assumed, and I guess could be wrong, that the message would show up in the console as they come in. But that's not what's happening. They're all showing up, but only after the last message is received. Then they all dump to the console at once.
Am I missing something, or is this how the message event works? If that's the way it works, is there a way around it so that the JS can act immediately when a message comes in instead of waiting until they're all in.