Esempio n. 1
0
func (t *ThriftExporter) Export(serviceName string, processor thrift.TProcessor) (err error) {
	var transport thrift.TServerTransport
	if t.Config.Secure {
		cfg := new(tls.Config)
		if cert, err := tls.LoadX509KeyPair(t.Config.CertFile, t.Config.KeyFile); err == nil {
			cfg.Certificates = append(cfg.Certificates, cert)
		} else {
			return err
		}
		transport, err = thrift.NewTSSLServerSocket(t.Provider.Addr, cfg)
	} else {
		transport, err = thrift.NewTServerSocket(t.Provider.Addr)
	}

	if err != nil {
		return err
	}
	server := thrift.NewTSimpleServer4(processor, transport, t.Config.TransFactory, t.Config.ProtocolFactory)

	err = t.Reg.Register(serviceName, t.Provider)
	if err != nil {
		fmt.Println("error when register service", err.Error())
		return
	}
	fmt.Println("Starting the simple server... on ", t.Provider.Addr)
	return server.Serve()
}
Esempio n. 2
0
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
	var transport thrift.TServerTransport
	var err error
	if secure {
		cfg := new(tls.Config)
		if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err == nil {
			cfg.Certificates = append(cfg.Certificates, cert)
		} else {
			return err
		}
		transport, err = thrift.NewTSSLServerSocket(addr, cfg)
	} else {
		transport, err = thrift.NewTServerSocket(addr)
	}

	if err != nil {
		return err
	}
	fmt.Printf("%T\n", transport)
	handler := NewCalculatorHandler()
	processor := tutorial.NewCalculatorProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", addr)
	return server.Serve()
}
func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
	var transport thrift.TServerTransport
	var err error
	if secure {
		cfg := new(tls.Config)
		if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err == nil {
			cfg.Certificates = append(cfg.Certificates, cert)
		} else {
			return err
		}
		transport, err = thrift.NewTSSLServerSocket(addr, cfg)
	} else {
		transport, err = thrift.NewTServerSocket(addr)
	}

	if err != nil {
		return err
	}
	fmt.Printf("%T\n", transport)

	announce_client.InitAnnounceUDP()
	fmt.Println("111")
	timestamp.InitTimeStamp()
	fmt.Println("222")
	cryptowrapper.GenerateRSAKey()
	fmt.Println("333")
	var c message.CalendarInfo
	c.Init()
	fmt.Println("444")
	var mul tcpNet.Multicast
	mul.Init(&c)
	fmt.Println("555")
	handler := NewMyServiceHandler()
	processor := calendar.NewMyServiceProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)

	fmt.Println("Starting the simple server... on ", addr)
	return server.Serve()
}