Browse Source

hdws add ping and replace client

dev
Tooooommy 4 years ago
parent
commit
014d5556cb
  1. BIN
      hdws/main_2
  2. 5
      hdws/ws/client.go
  3. 10
      hdws/ws/node.go

BIN
hdws/main_2

5
hdws/ws/client.go

@ -46,3 +46,8 @@ func (c *Client) WriteJson(body interface{}) error {
}
return c.Write(bs)
}
func (c *Client) CloseWithJson(body interface{}) {
bs, _ := json.Marshal(&body)
c.CloseWithMsg(bs)
}

10
hdws/ws/node.go

@ -115,6 +115,16 @@ func (t *Node) RegisterClient(c *Client) error {
if room, ok := t.rooms[c.RoomId]; ok {
room.rwmux.Lock()
defer room.rwmux.Unlock()
if oc, exist := room.clients[c.Id]; exist {
oc.WriteJson(&Message{
Type: "close",
Data: map[string]interface{}{
"error_code": 302,
"error_msg": "链接已被替换",
},
})
oc.Close()
}
room.clients[c.Id] = c
return nil
}

Loading…
Cancel
Save