packagecom.etc.test;importjava.io.IOException;importjava.io.ObjectOutputStream;importjava.io.OutputStream;importjava.net.Socket;importjava.util.Scanner;importcom.etc.entity.Emp;/*** 1. 实现传递对象;自定义对象; emp对象?
*
*@authorAdministrator
**/
public classClientHomework {public static voidmain(String[] args) {
Socket socket= null;
OutputStream os= null;
ObjectOutputStream oos= null;
Scanner input= newScanner(System.in);//处于监听状态,等待连接
try{//换这个socket是和serversocket进行交互的对象
socket = new Socket("127.0.0.1", 1234);
os=socket.getOutputStream();//写[序列化的过程]
oos = newObjectOutputStream(os);
System.out.println("请输入员工的id,name,age,address,job,sal");int id =input.nextInt();
String name=input.next();int age =input.nextInt();
String address=input.next();
String job=input.next();double sal =input.nextDouble();
Emp emp= newEmp(id, name, age, address, job, sal);
oos.writeObject(emp);
System.out.println("传输成功~");
input.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}finally{//释放资源
try{
socket.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}try{
socket.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}try{
os.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}try{
oos.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}