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 here, or https://godoc.org/ nhooyr.io/websocket instead.
Denne historien er fra April 2023-utgaven av Linux Format.
Start din 7-dagers gratis prøveperiode på Magzter GOLD for å få tilgang til tusenvis av utvalgte premiumhistorier og 9000+ magasiner og aviser.
Allerede abonnent ? Logg på
Denne historien er fra April 2023-utgaven av Linux Format.
Start din 7-dagers gratis prøveperiode på Magzter GOLD for å få tilgang til tusenvis av utvalgte premiumhistorier og 9000+ magasiner og aviser.
Allerede abonnent? Logg på
Create your first WebSocket service
Mihalis Tsoukalos explains how to use the Go programming language to work with the WebSocket protocol.
Fantastic Mr Firefox
Nick Peers takes a trip down memory lane to reveal the story behind the rise - and slight fall - of Mozilla's popular web browser.
Set up your terminal and email like it's 1983
Jump in the hot terminal time machine with Mats Tage Axelsson who emails from the command line using the latest technology.
Universal layer text effects with GIMP
Posters use them, films and presentations are hard to imagine without them: text effects. Attract attention with Karsten Günther and GIMP.
Jump to a federated social network
Nick Peers reveals how you can get up and running with this free, decentralised and non-profit alternative to Twitter.
Free our SOFTWARE!
Taking anything for granted is dangerous, so Jonni Bidwell and Mike Saunders revisit how the free software movement got started to help free us from proprietary tyranny!
Master RPI.GPIO
Les Pounder goes back to the early days of the Raspberry Pi - and his career with this classic library! -
Waveshare Zero to Pi3
Transform your Pi Zero into a Pi 3, they promised Les Pounder, but it's more like adding on go-faster stripes.
The Best OPEN SOURCE Software Ever!
In an attempt to trigger controversy, Michael Reed and Neil Mohr unequivocally state these are the greatest free software apps ever. Probably. We’re just trying to be helpful.
Linux-Mandrake 7
Simplicity and a wide range of applications make this a great distribution for all Linux users.