dhaber Posted August 25, 2013 Share Posted August 25, 2013 Massive Edit: I have removed the original message because the problem all came from confusion on my part as to how certain things needed to be done. I don't want to confuse others, so I've just changed this to a quick explanation of the current attempt. I have been converting my multiplayer CTF platformer demo to have a packed binary protocol instead of JSON. Initially I had been building the messages using Blob(), which made it really easy to append a list of data including typed arrays. The downside came when receiving the Blob on the other end. I had to use FileReader(), which is asynchronous. This made the code slower and more complicated, and seemed very unnecessary since the Blob was already in RAM and so there was no way it could block. It also introduced the potential for messages to process out of the received order (though I don't know if that would happen in reality.) Upon reevaluating I realized I never really need to use blobs. If I just send ArrayBuffers over websockets then I don't need FileReader() and so I don't hit the issues at all. The ArrayBuffers are easily built with a DataView() which also has the advantage of helping with controlling the endian of the data. I've started down this path, and while I don't yet have it converted, this seems simpler, potentially more efficient, and a lot more sensible than my initial try with Blobs. Does this sound about right? If anyone who has worked with websockets for these types of things has any thoughts or feedback, I'd be interested to hear. I'm going to try this out over the next day or so, and then I'll know for sure if I am on the right path. Quote Link to comment Share on other sites More sharing options...
Quetzacotl Posted August 26, 2013 Share Posted August 26, 2013 Well, you will need blob anyway for utf-8 strings. I'm sending typedarrays and whenever I need to send utf-8 I also use blob. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.