Linux Format

WEBSOCKET

OUR EXPERT

Mihalis Tsoukalos is a systems engineer and a technical writer. He is the author of Go Systems Programming and Mastering Go. You can reach him at @mactsouk.

This tutorial covers the WebSocket protocol and how to work with it using the Go programming language. We’re going to develop a WebSocket client and a WebSocket server that can interact with each other. In the process, we are also going to learn the basics of Unix signal handling in Go and how to test a WebSocket server using the Websocat command line utility as well as JavaScript.

Go is an open source programming language and WebSocket is an open protocol. The same applies to HTML and JavaScript, as well as Linux. People make a living from open source projects, tools, technologies and ideas, so please recognise that and contribute in any way you can. Many thanks to all these people!

Gorilla sockets

To develop a small yet fully functional WebSocket server, we’re using the gorilla/websocket (https:// github.com/gorilla/websocket) module. The server implements the Echo service, which means that it automatically returns its input to the client. It also expects to get client input before sending data back.

Apart from gorilla/websocket, the golang.org/x/ net/websocket package offers another way of developing WebSocket clients and servers. However, according to its documentation, golang.org/x/net/websocket lacks some features and it is advised that you use https://godoc.org/github.com/gorilla/ websocket, the one used

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format9 min read
Create Old-school Pixel Art Images
Credit: www.gimp.org Think of retro games and you’ll probably think of the pixellated look of titles released on consoles such as the NES. Games such as Bomberman and Kid Icarus worked within the limitations of ’80s technology, yet offered hours of f
Linux Format5 min read
Vintage PC options
Having got LMDE installed on our woefully underpowered EeePC, it became apparent that the machine wasn’t going to be very useful. Except for pandering to our sense of nostalgia. According to Systemd-analyze, it took a minute to boot (as far as the lo
Linux Format1 min read
Tom’s HARDWARE
No matter if you're building a PC, buying a laptop or learning about robots, Tom’s Hardware has all the comprehensive knowledge you need. Scan & Subscribe for free! ■

Related