(Go) Reconnecting websocket

Përfunduar Postuar 1 vit mё parё Paguhet në dorëzim
Përfunduar

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 (

"context"

"fmt"

"time"

"[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])

cancel()

}()

for {

select {

case <[login to view URL]():

go [login to view URL]()

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

return

default:

if ![login to view URL]() {

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

continue

}

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

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

return

}

for {

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

if err != nil {

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

continue

}

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

}

}

}

}

Golang

ID Projekti: #34050635

Rreth projektit

3 propozimet Projekti në distancë Aktiv 1 vit mё parё

Është zgjedhur fitues:

programcoder19

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 / orë
(9 Përshtypje)
3.8

3 profesionistë freelancer dërguan një ofertë mesatare prej $18/orë për këtë punë

ruggd71

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 Më shumë

$12 USD / orë
(0 Përshtypje)
0.0
moar55

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 Më shumë

$12 USD / orë
(0 Përshtypje)
0.0