11

I am running SocketIO on NodeJS and I don't care much about wide browsers support as it's my pet project where I want to use all the power of new technologies to ease the development. My concern is about how I should send large amounts of JSON data from server to client and back. Well, these amounts are not as large as could be for video or image binary data, I suppose not larger than hundreds of kilobytes per request.

Two scenarios I see are:

  1. Send a notification via WebSockets from server to client that some data should be fetched. Then client code runs a regular XHR request to server and gets some data via XHR.
  2. Send the whole data set over WebSockets from server to client. In this case I don't need to run any additional requests - I just get all the data via WebSockets.

I saw first case in Meteor.js, so I wondered the reasons of it. Please share your opinion.

Charles
  • 50,943
  • 13
  • 104
  • 142
Sergei Basharov
  • 51,276
  • 73
  • 200
  • 335
  • 2
    maybe this helps http://stackoverflow.com/questions/13010354/chunking-websocket-transmission – jAndy Apr 29 '13 at 12:04

1 Answers1

7

Websockets should support large data sets (up to 16 exabyte in theory), so from that point of view it should work fine. The advantage of XHR is that you will be able to observe progress over time and in general better tested for large data blocks. For example, I have seen websocket server implementations which (thinking retrospectively) wouldn't handle large data well, because they would load the entire data into memory (rather than streaming the data), but that's of course not necessarily the case for socket.io (dunno). Point in case: try it out with socket.io whilst observing memory usage and stability. If it works, definitely go with websockets, because long term the support for big data packages will only get better and definitely not worse. If it turns out to be unstable or if socket.io can't stream larger data files, then use the XHR construct.

Btw, just a google search turned up siofile, haven't looked into it that much, but it might be just the thing you need.

David Mulder
  • 26,123
  • 9
  • 51
  • 114
  • You should try and get into contact with Sergey whether he did some measurements/tries, if he did that would be very valuable information ;-) All I could share is the theory and a relevant github project. – David Mulder Jun 04 '13 at 12:31