Пример #1
0
func responder(port string) {
	// A simple echo operation with a 500ms response delay
	gotalk.HandleBufferRequest("echo", func(s *gotalk.Sock, op string, buf []byte) ([]byte, error) {
		println("responder: handling request")
		return buf, nil
	})

	// Start a server
	s, err := gotalk.Listen("tcp", "localhost:"+port)
	if err != nil {
		panic(err)
	}

	// Print when we receive heartbeats
	s.OnHeartbeat = func(load int, t time.Time) {
		fmt.Printf("responder: received heartbeat: load=%v, time=%v\n", load, t)
	}

	// Configure limits with a read timeout of one second
	s.Limits = gotalk.NewLimits(0, 0)
	s.Limits.SetReadTimeout(time.Second)

	// Accept connections
	println("responder: listening at", s.Addr())
	go s.Accept()
}
Пример #2
0
func responder(port string) {
	// A simple echo operation with a 500ms response delay
	gotalk.HandleBufferRequest("echo", func(s *gotalk.Sock, op string, buf []byte) ([]byte, error) {
		println("responder: handling request")
		time.Sleep(time.Millisecond * 400)
		return buf, nil
	})

	// Start a server
	s, err := gotalk.Listen("tcp", "localhost:"+port)
	if err != nil {
		panic(err)
	}

	// Limit this server to 5 concurrent requests (and disable streaming messages)
	s.Limits = gotalk.NewLimits(5, 0)

	// Accept connections
	println("listening at", s.Addr())
	go s.Accept()
}