WebSocket and Socket.IO Tutorials
Foreign Exchange Rates and Currency Conversion API
TraderMade is a quality data provider of exchange rates to hundreds of businesses. Live and historical Forex rates, real-time, tick data, all in one, robust and cost-effective solution.WebSocket Tutorial Socket.IO Tutorial
Introduction to WebSocket and Socket.IO
Already know what a websocket is then we will not bore you you can Start a Free Websocket or SocketIO trial by signing up.. Once you signup you can generate a Streaming API Key(userKey) which is can be used to access data for a trial period.
User expectations have changed a lot over the last couple of years we now live in an age where it is expected that content is instant and data is live. Web technology has improved and using WebSockets can now offer two-way (or full-duplex) data transfer between client and server.
The prime goal of WebSockets is to provide live data transfer over a persistent TCP socket connection.
To summarise how the protocol works: The client makes a request to the server and the server responds with a handshake, Once the client and the server have shaken hands so to speak they are free to send information back and forth at will.
All the data transfer takes place over a single TCP Socket and can be done on Port 80(WS) or Port 443(WSS), Most browsers now support WebSockets you can see if you browser support web sockets on this site.
Moving things forward...
Until the invention of WebSockets applications that needed live forex data in our world Forex Quotes, Charts and Alerts the only way to simulate live connections was to manipulate the HTTP protocol. This was done in a number of ways HTTP Streaming, HTTP Long Polling or SSE (Server Sent Events) but all of these had drawbacks.
HTTP Streaming works on a single connection between client and server. The client makes a request for live forex data and the server opens a connection. This connection is then kept alive with the server sending the data down the connection until it is terminated.
HTTP Long Polling
Long Polling achieved simulated live transfer by polling at regular intervals:
- The client makes a request to the server and waits for a response
- The server keeps the connection open until it is ready to send information to the client.
- The client receives the information and then sends a new request and the cycle starts again.
Server-Sent Events (SEE)
SSE implementation is a true push implementation but has several limitations but for one-way data it is also a good solution and I cover it in a different tutorial.
WebSocket the way forwardThe Web Socket protocol was standardized in 2011 and the WebSocket API in Web IDL by W3C. The WebSocket protocol allows true live communication between a client application (Web Browser or Client Side App) and a Web Server. WebSockets has a lower overhead than HTTP Polling and allows for live data transfer eliminating the delay between polls.
But wait what about Socket.IO....
Socket.IO is a WebSocket implementation wrapper that aids in the setup of WebSockets. Why make it hard when you can make it easy.
Web Socket vs Socket.IO
|WebSocket Wrapper||Protocol to establish a connection over HTTP|
|Event-Based Communication between Client and Server||Full Duplex Communication over TCP Connections|
|Handles Proxy and Load Balancing||Does not support Proxy or Load Balancing|
|Supports Broadcasting||Broadcasting not supported|
|Supports fallback options||Doesn't support fallback options|
Before we roll our sleeves up - Conclusion
WebSocket vs Socket.IO, not really much to say WebSockets are the protocol and Socket.IO is the quickest most robust method to get them implemented.
TraderMade offers its Live Forex Data JSON, FIX, Websocket and Socket.IO this is a Java wrapper class for the WebSocket protocol.