//Client 端:
Student pgt=new Student();
pgt.setName("name");
pgt.setAge("age");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(pgt);
oos.close();
byte[] bs = baos.toByteArray();
ByteBuffer buffer = ByteBuffer.wrap(bs, 0, bs.length);
while (buffer.hasRemaining() & client.write(buffer) != -1)
{
waitFor(1000);
}
buffer.flip();
//Server 端:
int reads = sc_key.read(byteBuffer);
byteBuffer.flip();
byte[] tmp_buffer = byteBuffer.array();
ByteArrayInputStream byteIn = new ByteArrayInputStream(tmp_buffer);
ObjectInputStream objIn = new ObjectInputStream(byteIn);
pgt = (Student) objIn.readObject();
objIn.close();
posted on 2007-01-31 15:08
wyg405 阅读(978)
评论(0) 编辑 收藏