Building a CLI chat app with Go and WebSockets

Click for: original source

In this tutorial you will elarn about more about the WebSockets protocol. Go provides a WebSocket library, but the Go team advises to use other solutions built by the community. By Gustavo Caso.

Author used websocket – a minimal and idiomatic WebSocket library for Go. At a time it was the most recent of all and had support for context and rate-limiting. Once we move away from deciding on the WebSocket library, we need a way to route request to our server, Go provides a fantastic http package for doing that.

The tutorial and provided code splits content between client and server. The server handles new WebSocket connections, listen to messages on those socket connections and broadcast messages to the right users. Also, it takes care of adding and removing users to different chat rooms.

The client connects to the server, listens to messages that are sent to it and print them. It also allows the users to submit new messages to the server. For the details follow the link to the original article. Nice one!

[Read More]

Tags programming golang software