Bite size ballerina gists to help you improve on your integration work.

Monday, May 29, 2017

Ballerina for simple server side Web Socket programs

WebSockets is one of those protocols that was invented to solve the transmission barrier posted by HTTP’s stateless request-response model. One of the key differentiators of it is its ability piggy back on HTTP infrastructure using the HTTP upgrade mechanism[1], this ability when coupled with the inbuilt support provided by HTML5 for client-side WebSockets programming, allowed it to emerge as a strong contender to win the full-duplex protocol war.

As with other transport/application protocols supported by Ballerina, a consistent programming interface is provided to put together WebSocket based server side programs with ease. The example found below demonstrates this capability.

To try out the example, create the folder structure <BALLERINA_HOME>/socketproxy/sample and copy the content into the two appropriately named bal files. Make an archive[2] and make a websocket client call to “ws://localhost:9090/socketproxy/ws”, find a sample python client attached(it requires python-websocket package to work).

Look to the websocket samples found in the ballerina 0.87 distribution to learn more about websocket programming with ballerina.

Note: the example above was constructed to demonstrate a simple use case involving websockets, a real world implementation should be built after careful analysis of the requirements.

About Me

Hello there, I hold a Bachelors in Computer Science from Edith Cowan University. My fascination with computers run back to the early 90s. I’ve been employed in IT since 2010, predominantly in a capacity of a Software Engineer. Over the years my technological interests have boiled down to Linux server crafting, Scripting languages, and a few other DevOps technologies.

When I’m not playing around with or consulting on technologies, which I care for, I find myself reading, blogging, appreciating art made with soul and spending time with my family.