As you noted, WebSockets have low overhead . The overhead is similar to regular TCP sockets: just two bytes per frame, compared to hundreds for AJAX / Comet.
Why a low-level, rather than some kind of built-in RPC function? Some thoughts:
It's not that difficult to take the existing RPC protocol and run it on the low-level socket protocol. You cannot go in the opposite direction and build a low-level connection if RPC overhead is assumed.
WebSockets support is pretty trivial to add to multiple languages ββon the server side. The payload is just a UTF-8 string, and almost every language has built-in effective support for this. The RPC mechanism is not much. How do you handle data type conversions between Javascript and the target language? Need to add a hint type to the Javascript side? What about variable length arguments and / or argument lists? Do you build these mechanisms if the language does not have a good answer? Etc.
What RPC mechanism will be modeled after? Would you choose an existing one (SOAP, XML-RPC, JSON-RPC, Java RMI, AMF, RPyC, CORBA) or a brand new one?
Once client support is versatile enough, many services that have a regular TCP socket will add WebSockets support (because it's pretty trivial to add). The same is not true if WebSockets was based on RPC. Some existing services may add an RPC layer, but for the most part, WebSockets services will be created from scratch.
For my noVNC project (VNC client using only Javascript, Canvas, WebSockets), low priority WebSockets is critical to achieving reasonable performance. While VNC servers do not support WebSockets, noVNC includes wsproxy, which is the common WebSockets for a TCP proxy.
If you are thinking about implementing an interactive web application and you havenβt decided on a server language, I suggest looking at Socket.IO , which is the library for node (server-side Javascript using Google V8).
In addition to all the advantages of node (the same language on both sides, very efficient, powerful libraries, etc.), Socket.IO gives you several things:
Provides a library of client and server frameworks for handling connections.
Detects the best transport supported by both the client and server. Transports include (from best to worst): native WebSockets, WebSockets using Flash emulation, various AJAX models.
A compatible interface no matter what transport is used.
Automatic encoding / decoding of Javascript data types.
It is not possible to create an RPC mechanism on top of Socket.IO, since both sides are the same language with the same native types.
kanaka
source share