interfacing wxSockets with data from Java's stream Topic is solved
-
- Earned a small fee
- Posts: 22
- Joined: Sat May 20, 2006 2:45 am
interfacing wxSockets with data from Java's stream
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.
-
- Earned a small fee
- Posts: 22
- Joined: Sat May 20, 2006 2:45 am
how would i do that?
the client sends the data in the form
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
the client sends the data in the form
Code: Select all
"packetname" & SEP_CHAR & "data1" & SEP_CHAR & "data2" & SEP_CHAR & END_CHAR
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

To use an output stream, you would need to wrap wxSocketBase in a wxSocketInputStream though.
So the code might look something like:
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.
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();