(Go) Reconnecting websocket

Need someone to look over my Go lang code (50 lines) and resolve an issue.

I am using the following package: [login to view URL] to automatically reconnect to a websocket in case of a disconnection. (Wifi drops, VPN is turned on/off, ethernet is accidently pulled etc).

I am able to reconnect to the websocket if a disconnection occurs but it will then constantly keep disconnecting and reconnecting at random intervals after the first disconnection. I need the connection to be stable after a reconnection occurs.

package main

import (




"[login to view URL]"


func main() {

ctx, cancel := [login to view URL]([login to view URL]())

ws := [login to view URL]{

KeepAliveTimeout: 10 * [login to view URL],


[login to view URL]("wss://[login to view URL]", nil)

go func() {

[login to view URL](2 * [login to view URL])



for {

select {

case <[login to view URL]():

go [login to view URL]()

[login to view URL]("Websocket closed %s", [login to view URL]())



if ![login to view URL]() {

[login to view URL]("Websocket disconnected %s", [login to view URL]())



if err := [login to view URL](1, []byte("test")); err != nil {

[login to view URL]("Error: WriteMessage %s", [login to view URL]())



for {

_, message, err := [login to view URL]()

if err != nil {

[login to view URL]([login to view URL]().UTC(), err)



[login to view URL]("Message received", [login to view URL]().UTC(), ":", string(message))





Skills: Golang

About the Client:
( 9 reviews ) preston, United Kingdom

Project ID: #34050635

Awarded to:


I will check the issue on my local machine, please send your 50 lines of code, I will do it for 30 USD fixed price instead of hourly

$30 USD / hour
(9 Reviews)

3 freelancers are bidding on average $18/hour for this job


Hello, I read your job details carefully and I'm interested in your project. I'm very familiar with the tech stacks you mentioned. I have rich experience in Golang. I will provide the perfect result and work with flexi More

$12 USD / hour
(0 Reviews)

Hello, I am a software developer with years of experience, and two of those in Golang development. I am currently working as a backend developer in a company in Germany using Golang. I believe I can help you resolve yo More

$12 USD / hour
(0 Reviews)