You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1017 B
Go

3 years ago
package client
import (
"dcg/game/pb"
"fmt"
"git.noahlan.cn/northlan/ngs/client"
"git.noahlan.cn/northlan/ngs/serialize/protobuf"
"log"
)
func NewClient(addr string) error {
c := client.NewClient()
chReady := make(chan struct{})
c.OnConnected(func() {
chReady <- struct{}{}
})
if err := c.Start(addr); err != nil {
return err
}
serializer := protobuf.NewSerializer()
c.On("onNewClient", func(data interface{}) {
var newClient pb.Client
serializer.Unmarshal(data.([]byte), &newClient)
log.Printf("服务器通知,由新客户端连接了房间: %+v\n", &newClient)
})
c.On("onInterval", func(data interface{}) {
var test pb.Test
serializer.Unmarshal(data.([]byte), &test)
log.Printf("服务器->客户端: %+v\n", &test)
})
<-chReady
c.Request("room.join", &pb.JoinRoomReq{LiveRoomId: 123456}, func(data interface{}) {
var resp pb.JoinRoomResp
serializer.Unmarshal(data.([]byte), &resp)
fmt.Printf("服务器->客户端: %+v\n", &resp)
})
for {
}
return nil
}