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

Sha*_*han 3 java sockets stream objectinputstream

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

 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.");
            }
Run Code Online (Sandbox Code Playgroud)

虽然它从断点传递但没有击中断点,它会暂停fobjIn并且不会执行.fobjOutfobjInfobjIn

Pet*_*rey 5

我会像这样保持简单

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();
}
Run Code Online (Sandbox Code Playgroud)