我有一个java客户端程序,它向服务器发送命令,服务器发回一个确认和一个响应字符串 .

我的客户端程序从客户端套接字获取输入流长度为0.但是,我使用wireshark进行调查 . Wireshark日志显示服务器已向我的ip发回了响应 . 不知何故,我的客户无法阅读它 .

My Client

public class Client {
    private static final String SERVER_ADDRESS = "192.168.64.79";
    private static final int TCP_SERVER_PORT = 6669;

    public void connect(String command) {
        BufferedReader in;
        try {
            // Socket skt = new Socket("50.128.128.254", 6669);//ip,port
            Socket clientSocket = new Socket(SERVER_ADDRESS, TCP_SERVER_PORT);// ip,port


            System.out.println(" client Socket created ..Enter command : ");


            PrintWriter outToServer = new PrintWriter(clientSocket.getOutputStream(), true);


            String ToServer = command;
            outToServer.println(ToServer);

             in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            System.out.print("Received string : length "+clientSocket.getInputStream().available()+"\n response:");

//          while (!in.ready()) {
//          }
            System.out.println(in.readLine()); // Read one line and output it

//          System.out.print("'\n");
            in.close();
            clientSocket.close();
            System.out.print("connection closed");

        } catch (Exception e) {
            System.out.print("Whoops! It didn't work!\n");
            e.printStackTrace();
        }

    }

}

WireShark results:

从服务器发送到我的客户端的9字节数据

enter image description here

Client output

Java客户端接收输入流长度0

enter image description here