套接字系统EOFException(ObjectInputStream)

时间:2017-12-09 09:57:10

标签: java sockets eofexception

嘿,我正在编写一个带有开放式src库的套接字系统... 每当我发送消息或其他东西时,我都会收到EOF异常

public Datapackage sendMessage(Datapackage message, int timeout) {
    try {
        Socket tempSocket;
        if (secureMode) {
            tempSocket = ((SSLSocketFactory) SSLSocketFactory.getDefault()).createSocket(address.getAddress(),
                    address.getPort());
        } else {
            tempSocket = new Socket();
            tempSocket.connect(address, timeout);
        }

        ObjectOutputStream tempOOS = new ObjectOutputStream(tempSocket.getOutputStream());
        message.sign(id, group);
        tempOOS.writeObject(message);

        ObjectInputStream tempOIS = new ObjectInputStream(tempSocket.getInputStream());
        Object raw = tempOIS.readObject();

        tempOOS.close();
        tempOIS.close();
        tempSocket.close();

        if (raw instanceof Datapackage) {
            return (Datapackage) raw;
        }
    } catch (Exception ex) {
        onLogError("[Client] Error while sending message:");
        ex.printStackTrace();
    }

    return null;
}

请任何人帮助我:c

1 个答案:

答案 0 :(得分:0)

对等方已关闭连接而未创建ObjectOutputStream。几乎可以肯定它根本不使用序列化。