I am fist connecting through vpn client then I am able to do telnet and also able to get response when i paste request string on terminal.
Same request if I am trying through java program, I am not getting any response.
I can see using netstat there is established TCP connection when i try through java. TCP 10.2.2.22:1154 184.23.23.61:7565 ESTABLISHED
Here is the java client code which sends the request.
Socket client = new Socket(serverIp, port);
OutputStream out = client.getOutputStream();
InputStream in = client.getInputStream();
String test = "TUE231363**";
StringBuffer response = new StringBuffer("response : ");
out.write(test.getBytes());
out.flush();
int c;
System.out.println("waiting for response.......>>>>>>>>>>>>>");
while ((c = in.read()) != -1) {
if (isEndOfResponse(c))
break;
System.out.print((char) c);
response.append(c);
}
client.close();
System.out.println(response.toString());
every time after few minutes [5-6 min] it exits without any response.
I am bit new to networking, can anyone suggest what I am missing.
I assume that you are telnetting to the same IP address and port that you are trying to connect to from Java.
The fact that telnet
connects, and your client also appears to connect would imply that the server is running, and that it has created an bound a ServerSocket
on the right IP / host. It is probably even calling accept
properly. But is seems like the server is either not reading the request at all, or it is failing to send a response.
Either way, the problem is most likely on the server side ... and there's not much we can say without seeing the server-side code.