L
liangbowen
Unregistered / Unconfirmed
GUEST, unregistred user!
how to use tcp socket to receive a class instance
-------------------------------------------------------------------------------
Author: liangbowen Jul 6, 2005 1:09 AM
I've created a class instance c2smsg, then
use PS.println(c2smsg) to send the instance to server.
But how can I receive the class and read the class members at the server side?
socket.getInputStream() can only receive String, byte[], or int...
-------------------------------------------------------------------------------
Re: how to use tcp socket to receive a class instance
Author: nickelb@ck Jul 6, 2005 1:15 AM (reply 1 of 3)
Write the socket input/output streams in ObjectInput/OutputStreams
-------------------------------------------------------------------------------
Re: how to use tcp socket to receive a class instance
Author: nickelb@ck Jul 6, 2005 1:16 AM (reply 2 of 3)
Damn, not 'Write', but 'Wrap'. Sorry
-------------------------------------------------------------------------------
Re: how to use tcp socket to receive a class instance
Author: liangbowen Jul 6, 2005 7:29 PM (reply 3 of 3)
To be clear, here is the sample code, i wrote a TestClass, and i want to send it and read it from the recieving side.
class TestClass{
String testSting = "i love you";
int port = 1024;
}
//send side
TestClass tc = new TestClass();
PrintWriter out=new PrintWriter(socket.getOutputStream());
...
out.println(tc);
//i am not sure if this is right
//send side end
//receive side
BufferedReader buf =new BufferedReader(new InputStreamReader(client.getInputStream()));
//then
what can ido
to buf to read out TestClass members? buf.readLine()?
//receive side end
-------------------------------------------------------------------------------
Author: liangbowen Jul 6, 2005 1:09 AM
I've created a class instance c2smsg, then
use PS.println(c2smsg) to send the instance to server.
But how can I receive the class and read the class members at the server side?
socket.getInputStream() can only receive String, byte[], or int...
-------------------------------------------------------------------------------
Re: how to use tcp socket to receive a class instance
Author: nickelb@ck Jul 6, 2005 1:15 AM (reply 1 of 3)
Write the socket input/output streams in ObjectInput/OutputStreams
-------------------------------------------------------------------------------
Re: how to use tcp socket to receive a class instance
Author: nickelb@ck Jul 6, 2005 1:16 AM (reply 2 of 3)
Damn, not 'Write', but 'Wrap'. Sorry
-------------------------------------------------------------------------------
Re: how to use tcp socket to receive a class instance
Author: liangbowen Jul 6, 2005 7:29 PM (reply 3 of 3)
To be clear, here is the sample code, i wrote a TestClass, and i want to send it and read it from the recieving side.
class TestClass{
String testSting = "i love you";
int port = 1024;
}
//send side
TestClass tc = new TestClass();
PrintWriter out=new PrintWriter(socket.getOutputStream());
...
out.println(tc);
//i am not sure if this is right
//send side end
//receive side
BufferedReader buf =new BufferedReader(new InputStreamReader(client.getInputStream()));
//then
what can ido
to buf to read out TestClass members? buf.readLine()?
//receive side end