Page 1 of 1

interfacing wxSockets with data from Java's stream

Posted: Sun Jun 04, 2006 9:24 pm
by xskater11x
I am making a program that is supposed to read from a stream from a java client, the tihng is, the java client does not send the length of the packet, it just reads until it finds and end_char (linebreak). Both of wxSocketBase's read functions require the size of the buffer, is there anyway to figure this out when the data is actually recieved (perhaps read from startchar to endchar), or does the client have to send the length.

Posted: Sun Jun 04, 2006 9:53 pm
by phlox81
Hm, does the client now send or read???

If you get every message without its length,
terminated by the endline, than, I think you
will have to read bytewise, until endline occurs.

Posted: Mon Jun 05, 2006 1:41 am
by xskater11x
how would i do that?

the client sends the data in the form

Code: Select all

"packetname" & SEP_CHAR & "data1" & SEP_CHAR & "data2" & SEP_CHAR & END_CHAR
and so on.

basically i want to find the length of the packet before it is put into Read function so i dont have to have a buffer array at MAX_LEN_PACKET and then trim it :roll:

Posted: Mon Jun 05, 2006 2:56 am
by jb_coder
You could read it into a wxStringOutputStream or wxMemoryOutputStream.

Posted: Thu Jun 08, 2006 10:03 am
by jb_coder
To use an output stream, you would need to wrap wxSocketBase in a wxSocketInputStream though.

So the code might look something like:

Code: Select all

wxSocketInputStream in(socketBase);

wxMemoryOutputStream out;
in.Read(out);

size_t dataSize = out.Stream().GetSize();
void* data = out.GetOutputStreamBuffer().GetBufferStart();
I haven't tried this code to verify that it will work, but it seems like it should if wxInputStream::Read() exits when the Java client stops sending data.