Færdiggjort

(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 (

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

}

}

}

}

Evner: Golang

Om klienten:
( 9 bedømmelser ) preston, United Kingdom

Projekt ID: #34050635

Tildelt til:

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 / time
(9 bedømmelser)
3.8

3 freelancere byder i gennemsnit $18/timen for dette job

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 Flere

$12 USD / time
(0 bedømmelser)
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 Flere

$12 USD / time
(0 bedømmelser)
0.0