interfacing wxSockets with data from Java's stream Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
xskater11x
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat May 20, 2006 2:45 am

interfacing wxSockets with data from Java's stream

Post 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.
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post 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.
xskater11x
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat May 20, 2006 2:45 am

Post 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:
jb_coder
Super wx Problem Solver
Super wx Problem Solver
Posts: 267
Joined: Mon Oct 18, 2004 10:55 am

Post by jb_coder »

You could read it into a wxStringOutputStream or wxMemoryOutputStream.
jb_coder
Super wx Problem Solver
Super wx Problem Solver
Posts: 267
Joined: Mon Oct 18, 2004 10:55 am

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