Esempio n. 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()
}
Esempio n. 2
0
func NewConnection(socket net.Conn, maxLen int, devs *DevicePKManager) *Connection {
	return &Connection{
		exit:           false,
		socket:         socket,
		devRequestId:   0,
		deviceManager:  devs,
		requestMap:     common.NewSafeMap(),
		requestQueue:   make(chan common.Message, maxLen),
		emptyRespQueue: make(chan common.Message, maxLen),
	}
}