Пример #1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	devConnManager := common.NewSafeMap()
	config := GateWayConfig{dmAddr: "localhost", dmPort: "7373", deviceAddr: "localhost",
		devicePort: "8384", appAddr: "localhost", appPort: "9394"}
	// outer device service dependency
	devManager := server.NewDevicePKManager(config.dmAddr+":"+config.dmPort, "zc-dm")
	if devConnManager == nil || devManager == nil {
		log.Fatal("device connection manager and device manager failed")
		return
	}

	// device gateway server start
	deviceServer := server.NewDeviceGatewayServer(devConnManager, devManager)
	if deviceServer == nil {
		log.Fatal("new device gateway server failed")
		return
	}
	go deviceServer.Start(config.deviceAddr + ":" + config.devicePort)
	go Monitor(devConnManager)
	// app gateway service start
	var serverConfig = &zc.ZServiceConfig{Port: config.appPort}
	appService := NewAppGatewayService(devConnManager, serverConfig)
	if appService == nil {
		log.Fatal("new app gateway service failed")
		return
	}
	appService.Start()
}
Пример #2
0
func main() {
	var serverConfig = &zc.ZServiceConfig{Port: "5354"}
	server := NewDeviceService("device", serverConfig)
	if server == nil {
		log.Fatal("new device server failed, exit")
		return
	}
	// TODO defer close all the connections
	server.Start()
}