Hello, everyone!
I have problem with serialize and send/recive message it over socket
(Windows7). Could you help me please. Thanx in advance. My code is:
Client side:
---------------
message::Message message;
int uniqueid;
printf("Vpiši ID odjemalca: ");
std::cin >> uniqueid;
printf("Sporočilo: ");
std::getline(std::cin, line);
if(line == "exit") break;
message.set_uniqueid(uniqueid);
message.set_bodytext(line);
int message_length = message.ByteSize();
google::protobuf::io::ArrayOutputStream array_output(szBuffer,
message_length);
google::protobuf::io::CodedOutputStream coded_output(&array_output);
coded_output.WriteVarint32(message_length);
message.SerializeToCodedStream(&coded_output);
if(send(sClient, szBuffer, message_length, 0) == SOCKET_ERROR){
printf("send() se ni izvedel zaradi napake %d\n", WSAGetLastError());
Server side:
----------------
(WSARecv(SocketInfo->Socket, &(SocketInfo->DataBuf), 1, &RecvBytes, &Flags,
NULL, NULL)
message::Message message;
google::protobuf::uint32 message_length;
google::protobuf::uint8 prefix[8192];
google::protobuf::io::CodedInputStream::ReadLittleEndian32FromArray(prefix,&message_length);
google::protobuf::io::ArrayInputStream
array_input(&(SocketInfo->DataBuf), message_length);
google::protobuf::io::CodedInputStream coded_input(&array_input);
message.ParseFromCodedStream(&coded_input);
printf("Podatki so bili uspešno prejeti z vodila ID: %d\n",
SocketInfo->Socket);
printf("Sporočilo: %s\n", message.bodytext());
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/protobuf/-/Wqk4VQTKBFIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.