Jump to content

Reading Blobs over Websockets


dhaber
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...