Read Data from a Java Socket

前端 未结 4 1408
被撕碎了的回忆
被撕碎了的回忆 2021-01-05 13:53

I have a Socket listening on some x port.

I can send the data to the socket from my client app but unable to get any response from the server socket.



        
4条回答
  •  时光说笑
    2021-01-05 14:22

    Here is my implementation

     clientSocket = new Socket(config.serverAddress, config.portNumber);
     BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    
      while (clientSocket.isConnected()) {
        data = in.readLine();
    
        if (data != null) {
            logger.debug("data: {}", data);
        } 
    }
    

提交回复
热议问题