예제 #1
0
func serviceThead(ms *util.MessageStream, clientProgramName string,
	serverProgramData *taosupport.TaoProgramData) {

	for {
		req, err := taosupport.GetRequest(ms)
		if err != nil {
			return
		}
		log.Printf("serviceThread, got message: ")
		taosupport.PrintMessage(req)

		terminate, _ := HandleServiceRequest(ms, serverProgramData,
			clientProgramName, req)
		if terminate {
			break
		}
	}
	log.Printf("simpleserver: client thread terminating\n")
}
예제 #2
0
// Handle service request, req and return response over channel (ms).
// This handles the one valid service request: "SecretRequest"
// and terminates the channel after the first successful request
// which is not generally what would happen in most channels.
// Note that in the future, we might want to use grpc rather than custom
// service request/response buffers but we don't want to introduce complexity
// into this example.  The single request response buffer is defined in
// taosupport/taosupport.proto.
func HandleServiceRequest(ms *util.MessageStream, serverProgramData *taosupport.TaoProgramData,
	clientProgramName string, req *taosupport.SimpleMessage) (bool, error) {

	//  The somewhat boring secret is the corresponding simpleclient's program name || 43
	secret := clientProgramName + "43"

	if *req.RequestType == "SecretRequest" {
		req.Data = append(req.Data, []byte(secret))
		taosupport.SendResponse(ms, req)
		log.Printf("HandleServiceRequest response buffer: ")
		taosupport.PrintMessage(req)
		return true, nil
	} else {
		log.Printf("HandleServiceRequest response is bad request\n")
		errmsg := "BadRequest"
		req.Err = &errmsg
		return false, nil
	}
}