Ejemplo n.º 1
0
//正在服务器上拿数据
func ServerListen(n, host string, c gof.App) {
	context = c
	jsv.Configure(c)
	serve := jsv.NewServer()
	serve.RegisterName("Member", &server.Member{})
	serve.RegisterName("Partner", &server.Partner{})

	addr, err := net.ResolveTCPAddr(n, host)
	checkErr(err)

	lis, err := net.ListenTCP(n, addr)
	checkErr(err)

	for {
		conn, err := lis.Accept()
		if err != nil {
			context.Log().Println("[Error]:", err.Error())
			continue
		}
		// set timeout
		t := time.Now().Add(5 * time.Minute)
		conn.SetDeadline(t)

		go receiveConn(conn, serve)
	}
}
Ejemplo n.º 2
0
func Configure(net, addr string, c gof.App) {
	var err error
	_conn, err = jsv.Dial(net, addr)

	if err != nil {
		fmt.Println("[TCP]: Connect Refused,", addr)
		os.Exit(1)
	}

	jsv.Configure(c)
	Member = &memberClient{conn: _conn}
	Partner = &partnerClient{conn: _conn}
	Redirect = &redirectClient{conn: _conn}
}