[protobuf] Delay in Sending Data

2010-10-21 Thread Kevin
I initially was try to get Protocol Buffers to work from Java to C++
over sockets.  I am still unsure how to do this but I decided to try
and test to see if I could get a Java to Java version working over
sockets and was successful.  However, I was experiencing a weirdness
which might be causing the error on the C++ side of things.

Below is my code on the server side.  Basically to make a long story
short I thought that closing the stream was causing my C++ code to
fail, so I put a little sleep in there to make sure it was still
connected.  Then when adding the java stuff I left the sleep in.
Basically, the code that receives the data will wait until the stream
is closed before reading the data.  I thought that flushing the data
would cause the data to be sent but that apparently has no effect.  Is
this my implementation or a problem with using the writeTo
function?

public class ProtoWriter {

public static void main(String[] args) {
Socket socket;
ServerSocket serverSocket;
ObjectOutputStream oos = null;

serverSocket = new ServerSocket(12345);
socket = serverSocket.accept();
oos = new ObjectOutputStream(socket.getOutputStream());

Measurement measurement = measBuilder.build();
measurement.writeTo(oos);
oos.flush();

TimeUnit.SECONDS.sleep(10);
oos.close();

-- 
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.



Re: [protobuf] Delay in Sending Data

2010-10-21 Thread Evan Jones

On Oct 21, 2010, at 1:21 , Kevin wrote:

Basically, the code that receives the data will wait until the stream
is closed before reading the data.  I thought that flushing the data
would cause the data to be sent but that apparently has no effect.  Is
this my implementation or a problem with using the writeTo
function?


The flush *should* be causing the data to be sent. The problem is on  
the reader side: the default read methods read until the end of the  
stream. You'll need to prepend a length. You may want to use  
parseDelimited(). See the following document, or search the archives  
for many conversations about this. Hope this helps,


Evan

http://code.google.com/apis/protocolbuffers/docs/techniques.html#streaming

--
Evan Jones
http://evanjones.ca/

--
You received this message because you are subscribed to the Google Groups Protocol 
Buffers group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.