(Go) Reconnecting websocket
$8-15 USD / orë
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))
}
}
}
}
ID Projekti: #34050635
Rreth projektit
Është zgjedhur fitues:
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