Data over TCP/IP socket
Posted on 2004-07-30
I'm looking out how to get data back and forth over TCP/IP.
I can see how to do char (see snippet below), but I don't know how to do other primitives (int, float) or how I would xfer an Object.
I guess I have to use something other than InputStreamReader/OutputStreamWriter.
What would I use?
InputStreamReader isr = null;
OutputStreamWriter osw = null;
isr = new InputStreamReader(socket.getInputStream());
osw = new OutputStreamWriter(socket.getOutputStream());
char cbuf=null; // character buffer to get chars from stream
isr.read(cbuf, 0, 100);
valid = true;
string = cbuf.toString();
osw.write(string, 0, string.length());