Skip to content

How to send bytes data from client side? #37

@yuta-hidaka

Description

@yuta-hidaka

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	} }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions