通过套接字传输 List<> 对象时出现问题



我不知道为什么,但突然间,我在通过TCP套接字发送和接收列表时遇到了问题,起初我成功地做到了。这是我的传输代码:发件人:

List<String> A = ....;
ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
System.out.println("Wrinting the answers");
out.writeObject(A);
System.out.println("Wrote the answers, now reading the flag");

我得到了正确的SOP,但是接收器进入等待状态:

ObjectInputStream in = new ObjectInputStream(soc.getInputStream());             
ls = (List<String>)in.readObject();
System.out.println("Recieved the list of results");

这里我没有得到SOP,接收器继续处于等待状态。补充:我之前成功地转移了列表,但后来我在这里和那里做了一些更改,现在不知道问题出在哪里。我实际上打算转移另一个列表<>也是,但只有当我找到第一个问题的解决方案时,我才会尝试!谢谢你的回答。。

试试这个:

ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
System.out.println("Wrinting the answers");
out.writeObject(A);
out.flush();  // flush the stream!
System.out.println("Wrote the answers, now reading the flag");

最新更新