gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:53:26 25 4
gpt4 key购买 nike

我不知道为什么,但突然间我在通过 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,接收器继续处于等待状态。补充一下:我之前成功地传输了列表,但后来我在这里和那里做了一些更改,现在不知道问题是什么。我实际上也打算转移另一个List<>,但只有当我得到第一个问题的解决方案时我才会尝试!谢谢您的回答..

最佳答案

试试这个:

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");

关于java - 通过套接字传输 List<> 对象时出现的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9341678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com