如何在java中向服务器发送对象?
客户:
Help h = new Help("Mattia Cammalleri","Informatica","18 Novembre 2020");
Socket s = new Socket("localhost", 8888);
ObjectOutputStream os = new ObjectOutputStream(s.getOutputStream());
ObjectInputStream is = new ObjectInputStream(s.getInputStream());
os.writeObject(h);
os.flush();
服务器:
ServerSocket ss = new ServerSocket(8888);
Socket s = ss.accept();
ObjectOutputStream os = new ObjectOutputStream(s.getOutputStream());
ObjectInputStream is = new ObjectInputStream(s.getInputStream());
Help h = (Help) is.readObject();
System.out.println("Richiesta " + h);
对象(实现可序列化):
public String alunno;
public String materia;
public String data;
为什么不起作用?
1条答案
按热度按时间egdjgwm81#
我是这样解决的:
客户:
服务器: