func ClientSender(user *User, c net.Conn) { defer user.Leave() for { select { case <-user.exit: // when receive signal then finish the program if DEBUG { gs.Log("Leave user id :" + gs.Itoa64(user.userID)) } return case m := <-user.recv: // on receive message msgTypeBytes := gs.WriteMsgType(m.msgType) // msg header + msg type msg := append(msgTypeBytes, m.content...) // '...' need when concat between slice+slice if DEBUG { gs.Log("Client recv, user id : " + gs.Itoa64(user.userID)) } _, err := c.Write(msg) // send data to client if err != nil { if DEBUG { gs.Log(err) } return } } } }
func ReqQuit(c net.Conn, userUID int64, data []byte) { req := new(gs_protocol.ReqQuit) req.UserID = proto.Int64(userUID) msgTypeBytes := gs.WriteMsgType(gs_protocol.Type_Quit) msg, err := proto.Marshal(req) gs.CheckError(err) data = append(msgTypeBytes, msg...) _, err = c.Write(data) if err != nil { fmt.Println(err) return } gs.Logf("client send : %v\n", req) }