[protobuf] Re: sending a message over TCP from a C++ client to a Java server

2010-10-13 Thread Paul
ok thanks a lot!  I ended up finding that my TCP send function was not
set up correctly.  Once that was fixed, it worked fine.  Thanks!

On Oct 13, 2:20 pm, Evan Jones  wrote:
> On Oct 13, 2010, at 16:49 , Paul wrote:
>
> > Thanks for the suggestion.  However, I am already prepending the
> > message size on the C++ side in the line:
> > coded_output->WriteVarint64(snap1.ByteSize());
>
> You may want to verify that the exact bytes that come out of  
> msg.SerializeToString (or related) are coming out the other end and  
> getting passed into parseDelimited. It might be helpful if you sent a  
> snippet of code where you are sending and receiving the messages, but  
> I can't think of anything off the top of my head.
>
> Evan
>
> --
> Evan Joneshttp://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.



Re: [protobuf] valgrind invalid write and double free errors

2010-10-13 Thread Evan Jones

On Oct 13, 2010, at 16:53 , CB wrote:

Any feedback on how to further debug this problem would be
appreciated.


You aren't doing anything strange like using dlopen() to dynamically  
load/unload libraries, are you? I can't think of anything obvious that  
might cause this kind of error. The FileDescriptorTables are "static"  
objects of sorts, I think. Are you calling ShutdownProtobufLibrary()  
somewhere? Maybe more than once? Memory leaks *will* be reported by  
valgrind if you don't call ShutdownProtobufLibrary(), but I don't know  
what could cause a double free.


Evan


--
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.



Re: [protobuf] Re: sending a message over TCP from a C++ client to a Java server

2010-10-13 Thread Evan Jones

On Oct 13, 2010, at 16:49 , Paul wrote:

Thanks for the suggestion.  However, I am already prepending the
message size on the C++ side in the line:
coded_output->WriteVarint64(snap1.ByteSize());


You may want to verify that the exact bytes that come out of  
msg.SerializeToString (or related) are coming out the other end and  
getting passed into parseDelimited. It might be helpful if you sent a  
snippet of code where you are sending and receiving the messages, but  
I can't think of anything off the top of my head.


Evan

--
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.



[protobuf] valgrind invalid write and double free errors

2010-10-13 Thread CB
I've been using protobuf 2.3.0 for several weeks, using
SerializeToString.  The
other day, I switched to using SerializeToOstream, and started seeing
the
following invalid write and double free errors reported by valgrind
when my
program is terminated;

==15778== Invalid write of size 4
==15778==at 0x6623464:
google::protobuf::FileDescriptorTables::~FileDescriptorTables()
(hashtable:532)
==15778==by 0x4D821BE: __run_exit_handlers (exit.c:78)
==15778==by 0x4D8222E: exit (exit.c:100)
==15778==by 0x4D69BDD: (below main) (libc-start.c:258)
==15778==  Address 0x635dc80 is 0 bytes inside a block of size 48
free'd
==15778==at 0x4024851: operator delete(void*) (vg_replace_malloc.c:
387)
==15778==by 0x4D821BE: __run_exit_handlers (exit.c:78)
==15778==by 0x4D8222E: exit (exit.c:100)
==15778==by 0x4D69BDD: (below main) (libc-start.c:258)
==15778==
==15778== Invalid free() / delete / delete[]
==15778==at 0x4024851: operator delete(void*) (vg_replace_malloc.c:
387)
==15778==by 0x4D821BE: __run_exit_handlers (exit.c:78)
==15778==by 0x4D8222E: exit (exit.c:100)
==15778==by 0x4D69BDD: (below main) (libc-start.c:258)
==15778==  Address 0x635dc80 is 0 bytes inside a block of size 48
free'd
==15778==at 0x4024851: operator delete(void*) (vg_replace_malloc.c:
387)
==15778==by 0x4D821BE: __run_exit_handlers (exit.c:78)
==15778==by 0x4D8222E: exit (exit.c:100)
==15778==by 0x4D69BDD: (below main) (libc-start.c:258)

The above are one example of several reports.  it appears there is one
set of
these for each proto message I have defined.

I've tried to recreate this error in a smaller example program for
several days
without success.  Am wondering if anyone on the list has seen this
problem, and
knows what might cause it?

I'm using SerializeToOstream in basically the following manner;


  char buf[512];
  std::stringbuf sbuf;
  sbuf.pubsetbuf((char*)buf, 512);
  std::ostream os(&sbuf);
  message.SerializeToOstream(&os);

Any feedback on how to further debug this problem would be
appreciated.

--CB

-- 
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.



[protobuf] Re: sending a message over TCP from a C++ client to a Java server

2010-10-13 Thread Paul
Thanks for the suggestion.  However, I am already prepending the
message size on the C++ side in the line:
coded_output->WriteVarint64(snap1.ByteSize());

is there anything else that stands out to you?

thanks for any further help.

On Oct 13, 12:56 pm, Evan Jones  wrote:
> On Oct 13, 2010, at 15:13 , Paul wrote:
>
> > On the client side (in C++), I open a TCP socket connection on the
> > same port with the server's IP address.  I serialize the message using
> > SerializeToCodedStream into an array using ArrayOutputStream.  After
> > serializing it, I send it over the TCP connection using my sendTCP
> > method which uses C++ sockets.
>
> SerializeToCodedStream does *not* prepend the message size. The Java  
> side is expecting that the message will start with the message length,  
> so that is probably why you are getting parse errors. You need to do  
> something like:
>
> codedOutput.WriteVarint32(msg.ByteSize());
> msg.SerializeToCodedStream(codedOutput);
> codedOutput.flush();
>
> ...
>
> Hope this helps,
>
> Evan
>
> (as an aside: the C++ API really should have an equivalent to  
> writeDelimitedTo and parseDelimited on the Java side).
>
> --
> Evan Joneshttp://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.



Re: [protobuf] sending a message over TCP from a C++ client to a Java server

2010-10-13 Thread Evan Jones

On Oct 13, 2010, at 15:13 , Paul wrote:

On the client side (in C++), I open a TCP socket connection on the
same port with the server's IP address.  I serialize the message using
SerializeToCodedStream into an array using ArrayOutputStream.  After
serializing it, I send it over the TCP connection using my sendTCP
method which uses C++ sockets.


SerializeToCodedStream does *not* prepend the message size. The Java  
side is expecting that the message will start with the message length,  
so that is probably why you are getting parse errors. You need to do  
something like:



codedOutput.WriteVarint32(msg.ByteSize());
msg.SerializeToCodedStream(codedOutput);
codedOutput.flush();

...


Hope this helps,

Evan

(as an aside: the C++ API really should have an equivalent to  
writeDelimitedTo and parseDelimited on the Java side).


--
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.



[protobuf] sending a message over TCP from a C++ client to a Java server

2010-10-13 Thread Paul
Hi,

I am new to protocol buffers, and I am trying to send a protocol
buffers message over TCP from a client computer running C++ to a
server computer running Java.  Both computers are 64 bit.

On the server side (in Java), I open a ServerSocket on a port, and get
a Socket after accepting the client's connection.  From the client
Socket (liveSock), I get an inputstream, which I pass to the handle
function, which calls parseDelimitedFrom on the inputstream.

On the client side (in C++), I open a TCP socket connection on the
same port with the server's IP address.  I serialize the message using
SerializeToCodedStream into an array using ArrayOutputStream.  After
serializing it, I send it over the TCP connection using my sendTCP
method which uses C++ sockets.

When I start running the two sides, the connection gets established.
However, when the client tries to send the data over TCP, the server
handle code crashes at parseDelimitedFrom with an
InvalideProtocolBufferException saying that the Message is missing
required fields.

I'm sure that my C++ TCP sockets work correctly, because I was able to
send text from C++ to Java without any problems.  If it helps, I can
also post the TCP code I have.

I am not sure what I am doing wrong.  I don't know if I am doing
things correctly on the server (Java) side.  Please let me know if you
see any problems!  Thanks a lot!

Paul



SERVER SIDE CODE:

ServerSocket sock = new ServerSocket(7003);

Socket liveSock = sock.accept();

handle(liveSock.getInputStream(), liveSock.getOutputStream());  //
handle defined below



HANDLE METHOD:

*** the protocol buffers message is called Snapshot ***

public static void handle(InputStream in, OutputStream output) {
   try {
   Snapshot snapshot = Snapshot.parseDelimitedFrom(in);
   while(snapshot != null) {
System.out.println("SNAPSHOT: " + snapshot.getId()
snapshot = Snapshot.parseDelimitedFrom(in);
}
   }
   catch (IOException e) {
  System.out.println("exception");
   }
}



CLIENT SIDE CODE:

*** the protocol buffers message is called snap1 ***

int sock = openSocketClientTCP("127.100.100.100", 7003);

char snap_buf2[snap1.ByteSize()+1];

ZeroCopyOutputStream* raw_output = new
ArrayOutputStream(snap_buf2,snap1.ByteSize()+1);
CodedOutputStream* coded_output = new CodedOutputStream(raw_output);

coded_output->WriteVarint64(snap1.ByteSize());
snap1.SerializeToCodedStream(coded_output);

delete coded_output;
delete raw_output;

sendTCP(sock, snap_buf2, snap1.ByteSize() + 1);



-- 
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.