My problem is that when I do
TcpClient con = new TcpClient ("127.0.0.1", 5432);
NetworkStream str = con.GetStream ();
Annoucement msg = new Annoucement ();
msg.typ = Annoucement.msgType.NOWY_GRACZ;
Serializer.SerializeWithLengthPrefix (str, msg, PrefixStyle.Base128);
Serializer.SerializeWithLengthPrefix (str, msg, PrefixStyle.Base128);
and I try to receive with custom library that uses protocol buffers
Connection con = server.accept();
Annoucement ann = con.receive();
cout << ann.typ() << endl;
ann = con.receive();
cout << ann.typ() << endl;
I can read only the first one. The second is wrong because the field typ is set to 0 whereas it should be 3. I think that function receive do something wrong but don’t know what.
Annoucement Connection::receive() throw(EmptySocket) {
CodedInputStream coded_input(raw_input);
google::protobuf::uint32 n;
coded_input.ReadVarint32(&n);
char *b;
int m;
coded_input.GetDirectBufferPointer((const void**)&b, &m);
Annoucement ann;
ann.ParseFromArray(b, n);
return ann;
}
one variable is initialised in constructor
FileInputStream* raw_input;
raw_input = new FileInputStream(s); //s is socket in this example communication
How can I modify it so that I can read consecutive messages from the socket?
From the reference:
I see these missing in your code:
coded_input.Skip()(should cover #1 above if used right)I’m guessing your problem is caused by #3 above, but I’m not sure until I see the
ParseFromArraycode.