Hi, I am not quite familiar with ObjectInput and OutputStream? Can someone post an example showing how to send an object via socket from server to client? Thank you for your help. Chris
matt hooker
Ranch Hand
Joined: Jul 26, 2001
Posts: 46
posted
0
Originally posted by Chris Ben: Hi, I am not quite familiar with ObjectInput and OutputStream? Can someone post an example showing how to send an object via socket from server to client? Thank you for your help. Chris
Hi Chris, try something like : try { socket = new Socket(host_name, port_number); out = new PrintWriter(new BufferedWriter(new ObjectOutputStream(socket.getOutputStream())), true); out.write(your_object); } catch (IOException io_ex) { System.err.println("Failed to create socket, " + host + ":" + port); socket = null; } Matt. p.s I will send a better (tested example) if you can't get something like this to work. Good Luck.
Its not what you do, its the way you say you've done it.
Chris Ben
Ranch Hand
Joined: Jan 15, 2001
Posts: 135
posted
0
Thank you for your help. I tried the polish the code, but I am stuck as the error below. My construct of socket failed to write out a object. And I even have no chance to try the server side. Any suggestions? Thanks a lot Chris