readLine()不返回任何值

时间:2018-03-12 18:41:53

标签: sockets readline

当我尝试执行此代码时,服务器正确获取我发送的数据,但客户端不会打印“响应”。程序在readLine()行进入无限循环,甚至不打印“Something”字符串。可能是什么问题?

class SecuritySystemClient {
    public static void main(String argv[]) throws Exception{

        byte [] a = {0, 0, 13, 98, 105, 108, 107, 101, 110, 116, 58, 99, 115, 52, 50, 49};

        Socket clientSocket = new Socket("localhost", 80);

        DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

        outToServer.write(a, 0, a.length);
        outToServer.flush();

        BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

        String response = inFromServer.readLine();
        System.out.println("Something");
        System.out.println(response);

        clientSocket.close(); 
    }
}

0 个答案:

没有答案