Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send bytes data from client side? #37

Open
yuta-hidaka opened this issue Oct 10, 2023 · 0 comments
Open

How to send bytes data from client side? #37

yuta-hidaka opened this issue Oct 10, 2023 · 0 comments

Comments

@yuta-hidaka
Copy link

Hi!

I'm trying to send an array byte as a client stream.
When I tried to send the data, the grpc got EOF and never got data from the client side.
In the client side, I'm using Uint8Array as a byte array.(grapc-gateway converts bytes to Uint8Array in javascript)
I'm new to WebSocket, was I missing something?

If you need more detail I will create a minimal reproduction code.

.proto message definition is

message HealthCheckRequest {
    string health = 1;
    bytes buf = 2;
}

client-side is like this.

const byteMessage = new TextEncoder().encode("test message"); // create bytes(Uint8Array) for request
ws.send(JSON.stringify({ health: 'abc', buf: byteMessage})); // this code not working(got EOF)
ws.send(JSON.stringify({ health: 'abc'}));  // without `buf` property work correctly. And I could get data on the server side.

and the server side is like this.

func (s *Server) HealthCheckBiDiStream(stream pb.TranslatorService_HealthCheckBiDiStreamServer) error {
	cnt := 0
	for {
		_, err := stream.Recv()
		if err != nil && err != io.EOF {
			log.Fatal(err)
			return err
		}
		if err == io.EOF {
			return nil
		}

		stream.Send(&pb.HealthCheckResponse{
			Health: fmt.Sprintf("OK %d", cnt),
		})

		if err != nil {
			log.Fatal(err)
			return err
		}
		cnt += 1

	}

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant