Take the 2-minute tour ×

I have asked several questions about protocol buffers about socket transferring...again,I got a problem when I want to receive data at the server end from the client.

here is the client end code:

int sendSystem(int sockfd, const void *buf, size_t nbytes, int flags) {
return ::send(sockfd, buf, nbytes, flags);


it's like the client do send data by integers standing for each byte.so the data was transferring in bytes.

here is the server end code:

GameRequest gameRequest=GameRequest.parseFrom(CodedInputStream.newInstance(socket.getInputStream()));
GameRequest gameRequest=GameRequest.parseDelimitedFrom(socket.getInputStream());
GameRequest gameRequest=GameRequest.parseFrom(socket.getInputStream());

I have tried each ways above to receive data and parse it...turns out none is a good way..mostly I just got a message as "the message has an invalid tag" or if I turn on the debug mode,it just stand by at the line of the code above and I can't move to next step or move into the calling method cuz the button step over and step into was disabled...

share|improve this question
I re-tagged this as "c++", since it's clearly not C. –  unwind Jan 16 '13 at 9:16
okay,thanks.... –  Ryan Zhu Jan 16 '13 at 9:23
protobuf streams do not know their own length; if you are keeping the stream open (i.e. if you don't close the outbound socket after send), then the receiver will not know that the data is finished. Unless you add "framing", such as a header with the number of bytes to read (and obviously process that at the receiver etc). This might explain some of the oddities.. –  Marc Gravell Jan 16 '13 at 10:52

Your Answer



Browse other questions tagged or ask your own question.