WebSockets allow a server application to connect to a web-based client written in JavaScript. This allows you to create web applications with two-way communication and to create updates such as chat rooms and more.
This recipe will explore writing a WebSocket server in Go and also demonstrate the process of a client consuming and communicating with a WebSocket server. It uses github.com/gorilla/websocket to upgrade a standard handler into a WebSocket handler and also to create the client application.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application, create a new directory called~/projects/go-programming-cookbook/chapter5/websocketand navigate to this directory.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter5/websocket
You should...