TCP IP客户端不接收任何输入,但从服务器发送数据包

时间:2016-01-14 10:02:14

标签: java sockets networking tcp tcpclient

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

  

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

我的客户

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结果:

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

enter image description here

客户端输出

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

enter image description here

0 个答案:

没有答案