go thrift

2019-01-16  本文已影响0人  明明就_c565

server端

type Handle struct {

    com.Dial

}

/*

func Dial_server_start() {

    transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

    protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

    serverTransport, err := thrift.NewTServerSocket(common.NetworkAddr)

    if err != nil {

        glog.Println("Error!", err)

        os.Exit(1)

    }

    processor := com.NewDialProcessor(Handler)

    server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)

    glog.Println("thrift server in", common.NetworkAddr)

    server.Serve()

}

*/

func Dial_server_start() {

    serverTransport, err := thrift.NewTServerSocket(common.DialAddr)

    if err != nil {

        glog.Println("Error!", err)

        os.Exit(1)

    } 

    processor := com.NewDialProcessor(Handle{})

    server := thrift.NewTSimpleServer2(processor, serverTransport)

    glog.Println("Dial thrift server in", common.DialAddr)

    server.Serve()

}

client端

func Register() {

    var err error

    Transport, err = thrift.NewTSocket(net.JoinHostPort(common.AgentIp, strconv.Itoa(common.AgentPort)))

    if err != nil {

        glog.Println(os.Stderr, "error resolving address:", err)

        os.Exit(1)

    } 

    ProtocolFactory = thrift.NewTBinaryProtocolFactoryDefault()

    RegisterClient = com.NewAgentClientFactory(Transport, ProtocolFactory)

    ReportClient = com.NewAnalysisClientFactory(Transport, ProtocolFactory)

    if err := Transport.Open(); err != nil {

        glog.Println(os.Stderr, "Error opening socket", err)

        os.Exit(1)

    } 

    //defer Transport.Close()

}

上一篇下一篇

猜你喜欢

热点阅读