The fatal flaw of Socket.io 0.9.x

Socket io 0.9

Socket.io in it’s current working state has a very interesting flaw we have been working through recently and it’s caused a great deal of confusion for everyone on board our team. This flaw even led to some heated arguments about objects and arrays and is all based around some really flawed misconceptions about Socket.io and how it functions.

Socket.io is written at its core in JavaScript and runs on the back-end in JavaScript through Node JS. However, this doesn’t mean that if you’re running an Android or iOS client you can’t use Socket.io. Instead you now have to use a Socket.io client library specifically for your device and interestingly enough we have client libraries for Android, iOS, and even server libraries for Ruby, Python, PHP, and many more.

All of these libraries though are NOT coded the same, and with some interesting reasons JavaScript reacts very differently than all of these other languages because I can do this:

socket.emit(“myEventName”,function(){return 35;});

This type of writing would be absurd in Objective C, but makes perfect sense in JavaScript. I can also do this:


Again, this as well is absurd, because these other languages aren’t dynamically typed like JavaScript. So each library seems to have its own take on how to communicate or use these little nuances and this ends up being a disaster for developers.

In Python for instance I run my socket.emit and I send an event name and I can ONLY send object 1.

In the particular Android library I use though it assumes that I could send as many objects as possible so it forces me to wrap those objects up in an array and then sends them to the server. However my server is written in Python so it doesn’t want an array, it wants just that one object.

Using Node JS as the backend when I receive the array I automatically translate that array into the object list that I expected.

In our iOS library however we pieced it together like we did in Python and assume that you can only send object 1.

This meant that as a team we had an extremely frustrating time piecing all of these things together, because the Android library is refusing to cooperate and wants to assume that it HAS to send an array, but the Python library and iOS library were so easy to customize to send objects that we implemented sending objects rather than arrays of objects. The proper way of doing this is probably with arrays of objects being received, but the fact that the different client libraries are confused about this leads me to understand why so many people conclude that Socket.io 0.9 is inherently broken and hopefully 1.0 will fix this. Socket.io gives you plenty of power when working in straight JavaScript, but once you start expanding into non dynamically typed languages this power causes far too much confusion to be valuable in its current version.

Leave a Reply


captcha *