流压缩 - 我做错了什么?

时间:2017-03-29 05:14:03

标签: java

对于我的一个项目,我想要压缩数据流并通过套接字进行传输。我到目前为止所做的是

        echoSocket = new Socket(SERVER_HOST_NAME, PORT);
        consoleIn = System.in;

        clientIn = echoSocket.getInputStream();
        clientInputUnzipper = new InflaterInputStream(clientIn);

        clientOut = echoSocket.getOutputStream();
        clientOutputZipper = new DeflaterOutputStream(clientOut);


        int r = 0, rc = 0;

        System.out.println("Connection achieved to HostName : " + SERVER_HOST_NAME + " on port " + PORT);

        while((r = consoleIn.read()) != END_OF_STREAM)
            clientOutputZipper.write(r)

在我的客户端。它似乎是发送第一个字节很好(我解决了客户端以确认这一点)。但我服务器端的读者似乎无法阅读。

        serverInputStream = clientSocket.getInputStream();
        serverInputUnzipper = new InflaterInputStream(serverInputStream);

        serverOutputStream = clientSocket.getOutputStream();
        serverOutputZipper = new DeflaterOutputStream(serverOutputStream); //used to send the data back to the client

        fileOutput = new FileOutputStream(log);
        fileFilterOutput = new FilterOutputStream(fileOutput);

        int r = 0, c = 0;

        while((r = serverInputUnzipper.read()) != END_OF_STREAM) //getting stuck on this line (waiting for input)

鉴于我已经发送了第一个字节,serverInputStream不应该收到它吗?但是,如果它停滞不前,我会假设它正在等待读取一些数据(serverInputUnzipper.read()函数)。为什么没有按预期接收数据字节?

提前致谢(我今天花了很多时间试图修复这个可能很简单的错误)

0 个答案:

没有答案