close connection

master
dingjun 4 years ago
parent 951abc1f55
commit a793eb11e1

@ -62,6 +62,8 @@ func _sendAndRecvTCP(addr string, msg string) string {
return "" return ""
} }
defer c.Close()
_, err = c.Write([]byte(msg)) _, err = c.Write([]byte(msg))
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
@ -83,14 +85,21 @@ func _sendAndRecvWS(addr string, msg string) string {
log.Errorln(err) log.Errorln(err)
return "" return ""
} }
resp.Body.Close()
if resp.StatusCode != http.StatusSwitchingProtocols { if resp.StatusCode != http.StatusSwitchingProtocols {
log.Errorf("dial ws code %d", resp.StatusCode) log.Errorf("dial ws code %d", resp.StatusCode)
return ""
} }
defer c1.Close()
err = c1.WriteMessage(websocket.BinaryMessage, []byte(msg)) err = c1.WriteMessage(websocket.BinaryMessage, []byte(msg))
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
return "" return ""
} }
_, d, err := c1.ReadMessage() _, d, err := c1.ReadMessage()
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)

Loading…
Cancel
Save