gpt4 book ai didi

java - 程序在 Java 中初始化对象输入流时暂停

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:17 24 4
gpt4 key购买 nike

在运行调试器时,程序暂停从服务器主输入输出流初始化对象流。以下是代码:

 public TFileReader(Client cli)throws Exception{
this.cli = cli;
fileSock = new Socket(cli.ServerIp(), cli.FilePort());
fobjIn = new ObjectInputStream(fileSock.getInputStream());
fobjOut = new ObjectOutputStream(fileSock.getOutputStream());
fobjOut.flush();

}

@Override
public void run(){

try{
System.out.println("file reader thread online");

fobjOut.writeObject(cli.Name());
fobjOut.flush();
String per = (String) fobjIn.readObject();
System.out.println(per+"video filing...");
if(!per.equals("OKF"))
{
throw new Exception("Error In retriving video.");
}

它在 fobjIn 处暂停并且不去执行 fobjOut 虽然 fobjIn 它从 fobjIn 断点但是不要打断点。

最佳答案

我会像这样保持简单

public TFileReader(Client cli) throws IOException {
this.cli = cli;
socket = new Socket(cli.ServerIp(), cli.FilePort());
out = new ObjectOutputStream(socket.getOutputStream());
out.flush();
in = new ObjectInputStream(socket.getInputStream());
}

public void writeObject(Object o) throw IOException {
out.writeObject(o);
out.reset();
out.flush();
}

public <T> T readObject() throw IOException {
return (T) in.readObject();
}

public void close() throws IOException {
in.close();
out.close();
socket.close();
}

关于java - 程序在 Java 中初始化对象输入流时暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14551211/

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