Skip to content

gnet客户端tcp4实现

Compare
Choose a tag to compare
@luyu6056 luyu6056 released this 17 Dec 03:39
· 16 commits to master since this release
c1c6294

使用例子

var GnetClient = gnet.Client(&gnetClient{}, gnet.WithCodec(&RpcCodec{}), gnet.WithTCPNoDelay(true))

func dail(network, addr string, rpc *RpcClient) (net.Conn, error) {
	c, err := GnetClient.Dial(network, addr)
	if err != nil {
		return nil, err
	}
	c.SetContext(rpc)
	conn := newClient(c)

	return conn, err
}

type gnetClient struct {
	*gnet.EventServer
}
func (*RpcClient) handleRead() {

}
func (rs *gnetClient) OnOpened(c gnet.Conn) (out []byte, action gnet.Action) {

	return
}
func (rs *gnetClient) OnClosed(c gnet.Conn, err error) (action gnet.Action) {
	if rpc, ok := c.Context().(*RpcClient); ok {
		rpc.reconnect <- nil
	}
	return gnet.None
}
func (rs *gnetClient) React(data []byte, c gnet.Conn) (action gnet.Action) {
}