You want to serialize your message to an array first (use
SerializeToString() or SerializeToArray()), then write that using send().
 Don't use FileOutputStream -- it is meant for stream-based I/O, not UDP.

On Fri, Sep 18, 2009 at 12:19 PM, <>wrote:

> Hello all,
> I am having trouble figuring out how to serialize data over a socket
> utilizing UDP protocol.  I am in C++ environment.  When writing to the
> socket without protocol buffers, I use the standard sendto() socket
> call which allows me to specify the port and IP address of the
> intended receiver of my UDP message.  When trying to send a protocol
> buffers message, this seems to be the recommended strategy on the
> google docs:
>        ZeroCopyOutputStream* raw_output   = new FileOutputStream
> (sock);
>        CodedOutputStream*    coded_output = new CodedOutputStream
> (raw_output);
>        coded_output->WriteRaw(send_data,strlen(send_data));
> There is no way to specify what the port and IP address is here,
> analogous to when using the standard sendto() socket writing call.  So
> my message never gets received by the intended recipient on the
> network.  I am aware that this is a raw message, not a PB message.
> Getting this raw message over the network is a first step in
> accomplishing the ultimate goal of getting the PB message over the
> network.
> Is there a way to get all of the bytes of a serialized PB message into
> raw form and then send them with sendto()?
> Any ideas? Thanks for any help.
> Jay
> >

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to