API that upgrades connection to use websocket. Contains server and client and testing how they communicate

Websocket Test API

How to execute

First run server using: make run-server.

Then run many client instances with: make run-client.

Then start typing in clients, and when you enter, text will be sent to server and returned as response.

Try yourself. Replaces question marks ? with other symbol !.

All methods are in main.go file

App can be compiled with go build main.go

App can be tested with go test

App can be executed with go run main.go

Optional parameter can be added port. Example go run main.go -port=8080 or server -port 8080

Type server --help for help

How it works

The server opens given or default port and listens for HTTP requests.

Created two endpoints. One is root to check if the server works.

Second is /ws. Expects for connection upgrade from HTTP to a WebSocket and waits for messages.

Received messages validated if it is text and all question marks replaced with exclamation marks.

Processed message is sent back to the client.

The connection closes when received not a valid message of client closes the connection.

The server should work in any environment

Client initializes http protocol change into WebSocket protocol.

The client sends all messages entered from console.

Receives processed messages and prints out to console.

I have chosen these approaches because they are documented by golang developers.

gorilla/websocket is mostly used in WebAPIs.

websocket.DefaultDialer.Dial method inside client automatically initializes http protocol change to WebSocket.

Unit tests not well done. It is possible to cover more situations.

References used

https://yalantis.com/blog/how-to-build-websockets-in-go/

https://quii.gitbook.io/learn-go-with-tests/build-an-application/websockets

https://stackoverflow.com/questions/47637308/create-unit-test-for-ws-in-golang

https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04

https://stackoverflow.com/questions/52964304/websocket-set-protocol-and-origin

https://www.geeksforgeeks.org/http-headers-content-type/

https://codeburst.io/unit-testing-for-rest-apis-in-go-86c70dada52d

https://www.youtube.com/watch?v=ttKgBttwzrg

https://stackoverflow.com/questions/55536439/how-can-i-upgrade-a-client-http-connection-to-websockets-in-golang-after-sending

https://golang.org/doc/articles/wiki/

https://stackoverflow.com/questions/55094133/how-to-send-some-event-update-from-http-handler-to-a-websocket-handler

Similar Resources

Just a PubSub Websocket Server

Eventual Agent Just a PubSub Websocket Server The eventual agent allows cluster local apps to subscribe and publish over network. Goals Provide a WebS

Dec 24, 2022

HLive is a server-side WebSocket based dynamic template-less view layer for Go.

HLive is a server-side WebSocket based dynamic template-less view layer for Go.

HLive HLive is a server-side WebSocket based dynamic template-less view layer for Go. HLive is a fantastic tool for creating complex and dynamic brows

Jan 8, 2023

Websocket server, implemented flow Room style

ignite A websocket server module. Require redis to scale to multi nodes. Client/server message follow format type Message struct { Event string

Apr 10, 2022

A simple server to convert ATK-IMU901 serial data into websocket stream

A simple server to convert ATK-IMU901 serial data into WebSocket stream.

Jan 31, 2022

A modern, fast and scalable websocket framework with elegant API written in Go

A modern, fast and scalable websocket framework with elegant API written in Go

About neffos Neffos is a cross-platform real-time framework with expressive, elegant API written in Go. Neffos takes the pain out of development by ea

Dec 29, 2022

Websocket API Gateway that allows to subscribe on notifications about price changes of financial instruments

websocket-api-gateway Websocket API Gateway that allows to subscribe on notifications about price changes of financial instruments To test connection

Dec 5, 2021

A fast, well-tested and widely used WebSocket implementation for Go.

Gorilla WebSocket Gorilla WebSocket is a Go implementation of the WebSocket protocol. Documentation API Reference Chat example Command example Client

Jan 2, 2023

Minimal and idiomatic WebSocket library for Go

websocket websocket is a minimal and idiomatic WebSocket library for Go. Install go get nhooyr.io/websocket Highlights Minimal and idiomatic API First

Dec 31, 2022

Go-distributed-websocket - Distributed Web Socket with Golang and Redis

Go-distributed-websocket - Distributed Web Socket with Golang and Redis

go-distributed-websocket Distributed Web Socket with Golang and Redis Dependenci

Oct 13, 2022
Encrypted-websocket-chat - Encrypted websocket chat using golang

Encrypted websocket chat First version written in python This version should be

Sep 15, 2022
Websocket-chat - A simple websocket chat application
Websocket-chat - A simple websocket chat application

WebSocket Chat App This is a simple chat app based on websockets. It allows user

Jan 25, 2022
BrisGolang is a Go implementation of the game of briscola using the WebSocket protocol for client/server communication.

BrisGolang BrisGolang is a Go implementation of the game of briscola using the WebSocket protocol for client/server communication. Usage You can play

Nov 1, 2021
Websocket server. Get data from provider API, clean data and send to websoket, when it's changed.

Описание Сервис получает данные по киберспортивным матчам CS:GO от провайдера, структурирует, очищает от лишнего и отправляет всем активным вебсокет к

Apr 6, 2022
This application shows how to use the websocket package to implement a simple web chat application.

Chat Example This application shows how to use the websocket package to implement a simple web chat application. Running the example The example requi

Nov 14, 2021
WebSocket Command Line Client written in Go

ws-cli WebSocket Command Line Client written in Go Installation go get github.com/kseo/ws-cli Usage $ ws-cli -url ws://echo.websocket.org connected (

Nov 12, 2021
A tiny command line websocket client written in Go

wsc A simplistic tool for sending and receiving websocket messages from a command line. Mainly useful to test websocket servers. Getting started: $ go

Jan 12, 2022
Websocket client sample integration (go) for FairOS.

fairos-websocket-client FairOS websocket clients should be an extension on the FairOS OpenAPI specification, with introduction of events for seamless

Jul 14, 2022
Client Implementation of eosio state-history websocket.

Client Implementation of eosio state-history websocket.

Dec 6, 2022
Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.

websocketd websocketd is a small command-line tool that will wrap an existing command-line interface program, and allow it to be accessed via a WebSoc

Dec 31, 2022