since I use WebSocket connections on more regular bases, I was interested in how everything works under the hood. Thus, I have been breaking into endless specifications for a long time, but so far I have not been able to find anything about how to spoof the stream itself.
The WebSocket protocol calls it data frames (which describes a clean data stream, which is why it is also called non-control frames). As far as I understand the specification, there is no defined maximum length and no specified MTU (maximum transmission unit), which, in turn, means that one frame of WebSocket data can contain, according to the specification (!) An infinite amount of data (please correct me if I'm wrong, I'm still involved in this).
After reading this, I instantly set up my small Node WebSocket server. Since I have a strong history of Ajax (also streaming and Comet), my expectations were original: "There must be some kind of interactive mode for reading data while it is being transmitted." But I'm wrong, right?
I started small with 4kb of data.
server
testSocket.emit( 'data', new Array( 4096 ).join( 'X' ) );
and, as expected, it will come to the client as one data block
client
wsInstance.onmessage = function( data ) { console.log( data.length );
therefore, I increased the payload, and I really expected again that at some point the client-side onmessage would fire again, effectively blocking the transfer. But, to my shock, this never happened (node-server, tested on the side of Firefox, chrome and safari on the client side). My biggest payload was 80 MB
testSocket.emit( 'data', new Array( 1024*1024*80 ).join( 'X' ) );
and he still arrived in one big block of data on the client. Of course, this takes some time, even if you have a pretty good connection. Questions here
- Is it possible to cut these streams similar to ReadyState3 XHR mode?
- Is there a size limit for one ws data frame?
- Are these websites that should not transmit such large payloads? (which would make me wonder again why there is no certain maximum size)
I can still look at WebSockets from the wrong point of view, maybe the need to send large amounts of data simply does not exist, and you have to completely or partially split any data before sending?