Reputation:
back code (Go):
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
// ..................
http.HandleFunc("/notifications", func(w http.ResponseWriter, r *http.Request) {
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
logrus.Panic(err)
}
})
front (JS)
conn = new WebSocket("ws://host:2020/notifications");
conn.onmessage = function (event) {
if(event.data != "") {
newMessage(JSON.parse(event.data));
}
};
in this line logrus.Panic(err) sometimes get an error
write tcp 10.3.0.14:2020->10.2.1.87:58691: wsasend: An established connection was aborted by the software in your host machine.
what could it be, something with the network?
Upvotes: 1
Views: 12271
Reputation: 747
From the error code , I assume you are building this in windows and the error indicates that there is some issue in your host machine , that is your windows desktop/laptop . May be firewall or antivirus software or some other third party software or your internet connectivity if you connect to server over internet.
Use wireshark to trace the packet flow to understand bit more. As per RFC for websocket , it uses tcp connection , use proper tcp filters with wireshark to capture the packets and inspect from which point the connection has closed.
Upvotes: 2