1
我的問題是,當我做C++應用程序不能接收從C#應用程序連續消息
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);
,我嘗試接收與使用協議緩衝區
Connection con = server.accept();
Annoucement ann = con.receive();
cout << ann.typ() << endl;
ann = con.receive();
cout << ann.typ() << endl;
我可以閱讀定製庫只有第一個。第二個是錯誤的,因爲字段typ
設置爲0,而它應該是3.我認爲該函數接收做錯了,但不知道是什麼。
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;
}
一個變量被初始化在構造函數中
FileInputStream* raw_input;
raw_input = new FileInputStream(s); //s is socket in this example communication
如何修改它,這樣我可以閱讀從插座連續消息?