Skip to content

Thunder is a network transport tool kit powered by gnet

Notifications You must be signed in to change notification settings

Crearns/thunder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thunder

Thunder is a network transport tool kit powered by gnet

it can build a high performance RPCServer or RPCClient easily. It supports send request synchronously、asynchronously and oneway

How to use

server

func main() {
    s := NewRPCServer(config.NewDefaultServerConfig(9003))
    // register your func corresponding the code to process the packet with the code
    s.RegisterProcessor(1, func(p *protocol.Packet, addr net.Addr) *protocol.Packet {
        resp := protocol.NewPacket(1, nil, nil)
        resp.Remark = "response message"
        return resp
    })
    // call the start to start the server
    s.Start()
}

client

func main() {
    addr, err := net.ResolveTCPAddr("", "127.0.0.1:9003")
    if err != nil {
        panic(err)
    }
    c := NewRPCClient(config.NewClientConfig())
    // async
    err = c.InvokeAsync(context.TODO(), addr, protocol.NewPacket(1, nil, nil), func(future *ResponseFuture) {
        c.logger.Infof("%+v", future.Response)
    }, time.Second * 3000)
    if err != nil {
        panic(err)
    }
    
    // sync
    p, err := c.InvokeSync(context.TODO(), addr, protocol.NewPacket(1, nil, nil), time.Second * 3000)
    if err != nil {
        panic(err)
    }
    fmt.Printf("%+v", p)
}

About

Thunder is a network transport tool kit powered by gnet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages