Commit 5b3c379f authored by haoyanbin's avatar haoyanbin

fml

parent d0eee34a
...@@ -129,7 +129,7 @@ type Conversation struct { ...@@ -129,7 +129,7 @@ type Conversation struct {
// reads from this goroutine. // reads from this goroutine.
func (c *Client) readPump() { func (c *Client) readPump() {
defer func() { defer func() {
fmt.Println("连接己关闭或者断开,正在清理对像") fmt.Println("连接己关闭或者断开,正在清理对像", c.User)
c.conn.Close() c.conn.Close()
//触发连接关闭的事件回调 //触发连接关闭的事件回调
c.onClose() //先执行完关闭回调,再请空所有的回调 c.onClose() //先执行完关闭回调,再请空所有的回调
...@@ -174,17 +174,17 @@ Loop: ...@@ -174,17 +174,17 @@ Loop:
websocket.CloseTLSHandshake) { websocket.CloseTLSHandshake) {
fmt.Println("err:", err) fmt.Println("err:", err)
c.onError(errors.New("连接ID:" + c.Id + "ReadMessage Is Unexpected Close Error:" + err.Error())) c.onError(errors.New("连接ID:" + c.Id + "ReadMessage Is Unexpected Close Error:" + err.Error()))
//c.closeChan<-true;
goto Loop1 goto Loop1
} }
c.onError(errors.New("连接ID:" + c.Id + "ReadMessage other error:" + err.Error())) c.onError(errors.New("连接ID:" + c.Id + "ReadMessage other error:" + err.Error()))
//c.closeChan<-true;
goto Loop1 goto Loop1
} }
c.conn.SetReadDeadline(time.Now().Add(pongWait)) c.conn.SetReadDeadline(time.Now().Add(pongWait))
c.pingPeriodTicker.Reset(pingPeriod) c.pingPeriodTicker.Reset(pingPeriod)
c.lastReceiveTime = time.Now() c.lastReceiveTime = time.Now()
//msg, err := unMarshal(message)
msg := &SendMsg{} msg := &SendMsg{}
UnserislizeJson(message, msg) UnserislizeJson(message, msg)
if err != nil { if err != nil {
...@@ -278,12 +278,8 @@ Loop: ...@@ -278,12 +278,8 @@ Loop:
//glog.Error("连接ID:"+c.Id,"wsServer发送消息失败,一般是连接channel已经被关闭:(此处服务端会断开连接,使客户端能够感知进行重连)") //glog.Error("连接ID:"+c.Id,"wsServer发送消息失败,一般是连接channel已经被关闭:(此处服务端会断开连接,使客户端能够感知进行重连)")
goto Loop1 goto Loop1
} }
//message, err := marshal(d)
message := SerializeJson(d) message := SerializeJson(d)
//if err != nil {
// c.onError(errors.New("接收数据ProtoBuf编码失败!!连接ID:" + c.Id + "原因:" + err.Error()))
// break Loop
//}
w, err := c.conn.NextWriter(websocket.TextMessage) w, err := c.conn.NextWriter(websocket.TextMessage)
if err != nil { if err != nil {
goto Loop1 goto Loop1
......
...@@ -262,7 +262,7 @@ func Send(msg *SendMsg) error { ...@@ -262,7 +262,7 @@ func Send(msg *SendMsg) error {
} }
//} //}
} else { } else {
fmt.Println(1) fmt.Println("接收方数据有误", c)
} }
} }
...@@ -278,7 +278,7 @@ func Send(msg *SendMsg) error { ...@@ -278,7 +278,7 @@ func Send(msg *SendMsg) error {
} }
} }
} else { } else {
fmt.Println(2) fmt.Println("发送方数据有误", c)
} }
} }
} }
......
...@@ -78,7 +78,7 @@ func ws(w http.ResponseWriter, r *http.Request) { ...@@ -78,7 +78,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
userInfo, err := pool.GetClientInfo(headData) userInfo, err := pool.GetClientInfo(headData)
if err != nil { if err != nil {
fmt.Println("用户信息报错:", err) fmt.Println("用户:", headData, "信息报错:", err)
return return
} }
...@@ -91,7 +91,7 @@ func ws(w http.ResponseWriter, r *http.Request) { ...@@ -91,7 +91,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
Goroutine: 100, Goroutine: 100,
}) })
fmt.Println(client.User, "实例化连接对象完成") //fmt.Println(client.User, "实例化连接对象完成")
//连接成功回调 //连接成功回调
client.OnOpen(func() { client.OnOpen(func() {
...@@ -109,7 +109,7 @@ func ws(w http.ResponseWriter, r *http.Request) { ...@@ -109,7 +109,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
//发送消息给指定的ToClientID连接 //发送消息给指定的ToClientID连接
err := pool.Send(msg) err := pool.Send(msg)
if err != nil { if err != nil {
fmt.Println("pool.Send(msg):", err.Error()) fmt.Println("pool.Send(msg)err:", err.Error())
} }
//发送消息给当前连接对象 //发送消息给当前连接对象
//err = client.Send(msg) //err = client.Send(msg)
...@@ -151,16 +151,15 @@ func ws(w http.ResponseWriter, r *http.Request) { ...@@ -151,16 +151,15 @@ func ws(w http.ResponseWriter, r *http.Request) {
fmt.Println("专家关闭连接", client.User) fmt.Println("专家关闭连接", client.User)
} }
pool.DelClient(client.User) pool.DelClient(client.User)
fmt.Printf("连接己经关闭%s", client.Id)
}) })
client.OnError(func(err error) { client.OnError(func(err error) {
fmt.Printf("连接%s错误信息:%s", client.Id, err.Error()) fmt.Println("连接错误信息:", client.Id, err.Error())
}) })
//开启连接 //开启连接
client.OpenClient(w, r, head) client.OpenClient(w, r, head)
fmt.Println(client.Id, "开启连接") //fmt.Println(client.Id, "开启连接")
r.Close = true r.Close = true
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment