I managed to solve my problem now. I used the blah.Bytesize() function
instead of sizeof( blah.c_str() ) when sending the message size :3.
Someone should really add to documentation about Sending and Receiving
info between Server and Clients to prevent further Headaches. (Not
small ones either!)
On 10 Nov, 22:18, Kenton Varda [EMAIL PROTECTED] wrote:
It looks like you are assuming that sends and receives on your TCP stream
will match up 1:1. This isn't actually the case. A TCP connection is a
stream of bytes, not packets. A single read on the receiving end may
receive only part of a packet, or it may receive multiple packets.
So, you really need to write the size of your message first, then make sure
to read exactly that many bytes on the receiving end.
On Mon, Nov 10, 2008 at 12:51 PM, ChJees [EMAIL PROTECTED] wrote:
It looked like this before i sent the data: (Debug)
type: 14
Login {
name: Test
password: nil
}
And i got this on the receiving end: (Debug)
type: 14
Login {
14 {
}
}
I can't figure out what in the world which could be changing data...
Notice: I am using wxWidgets for UI and SFML for Networking.
Here are the sending and recieving methods:
//Server side
this-TCP-Receive(this-TCPBuffer, sizeof( this-TCPBuffer ), this-
RecievedSize) //- Is in a If structure
net_protocol::NMessage RcvdMsg;
std::string Tmp(this-TCPBuffer);
RcvdMsg.ParseFromString( Tmp )
//Client side
net_protocol::NMessage Msg;
Msg.set_type( Network::MsgType::RECIEVE_LOGIN_INFO );
net_protocol::LoginInfo *LoginInfos;
LoginInfos = Msg.mutable_login();
LoginInfos-set_name( this-name-GetValue() );
LoginInfos-set_password( this-password-GetValue() );
std::string Tmp;
Msg.SerializeToString(Tmp);
this-fParent-Socket.Send( Tmp.c_str(), sizeof( Tmp.c_str() ) );
On 10 Nov, 20:40, Kenton Varda [EMAIL PROTECTED] wrote:
I don't see anything wrong with your code. What kind of error are you
seeing? Are you sure that the bytes you passed in to the parser on the
receiving end are exactly the same as what came out of the serializer on
the
sending side?
On Sun, Nov 9, 2008 at 6:40 AM, [EMAIL PROTECTED] wrote:
I wonder if there are any reasons to why this would fail to parse on
the Server side of a game which a few friends me are making.
||Protocol:
package net_protocol;
//Login Protocol 2
message LoginInfo {
required string name = 1;
required string password = 2;
}
//Message Protocol 3
message ChatMessage {
required string name = 1;
required string body = 2;
}
//The Protocol Main
message NMessage {
required int32 type = 1;
optional LoginInfo type2 = 2;
optional ChatMessage type3 = 3;
}
||Code which sends the Protocol:
net_protocol::NMessage Msg;
Msg.set_type( Network::MsgType::RECIEVE_LOGIN_INFO );
net_protocol::LoginInfo *LoginInfos;
LoginInfos = Msg.mutable_type2();
LoginInfos-set_name( this-name-GetValue().c_str() );
LoginInfos-set_password( this-password-GetValue().c_str() );
//Send away it here with some Network stuff
When the server gets that and tries to parse it so does it autofail.
Just sending the NMessage without any optional structures work fine.
And the documentation are vague at it's best to describe how to use
optional messages.
I would be grateful if someone could give me more insight on this :).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
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
-~--~~~~--~~--~--~---