I have a java client program that sends a command to server and server sends back an acknowledgement and a response string.
My client program gets the input stream length from client socket as 0. But, I used wireshark to investigate. Wireshark logs show that the server has sent back a response to my ip. Somehow, my client is unable to read it.
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:
9bytes of data sent from server to my client
Client output
Java client receives inputstream length 0