Browse Source

Ignore empty messages in IO loop

motorcontrol
Tim Schuster 2 years ago
parent
commit
6e5be7c38b
Signed by: Tim Schuster <mail@timschuster.info> GPG Key ID: F9E27097EFB77F61
1 changed files with 6 additions and 0 deletions
  1. 6
    0
      webs.go

+ 6
- 0
webs.go View File

@@ -117,6 +117,9 @@ func readLoop(conn *websocket.Conn, stop <-chan struct{}) (<-chan []byte) {
117 117
 				return
118 118
 			default:
119 119
 				_, m, err := conn.ReadMessage()
120
+				if strings.TrimSpace(string(m)) == "" {
121
+					continue
122
+				}
120 123
 				if err != nil {
121 124
 					fmt.Printf("Error on WS read: ", err)
122 125
 				}
@@ -135,6 +138,9 @@ func writeLoop(conn *websocket.Conn, stop <-chan struct{}) (chan<- []byte) {
135 138
 			case <-stop:
136 139
 				return
137 140
 			case msg := <-outChan:
141
+				if strings.TrimSpace(string(msg)) == "" {
142
+					continue
143
+				}
138 144
 				err := conn.WriteMessage(websocket.BinaryMessage, msg)
139 145
 				if err != nil {
140 146
 					fmt.Printf("Error on WS write: ", err)

Loading…
Cancel
Save