简体   繁体   English

没有从服务器得到任何响应,但能够从 telnet 得到响应

[英]not getting any response from server, but able to get response from telnet

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.我首先通过 vpn 客户端进行连接,然后我可以执行 telnet 操作,并且当我在终端上粘贴请求字符串时也可以得到响应。

Same request if I am trying through java program, I am not getting any response.如果我尝试通过 java 程序进行相同的请求,则没有得到任何响应。

I can see using netstat there is established TCP connection when i try through java.当我尝试通过java时,我可以看到使用netstat建立了TCP连接。 TCP 10.2.2.22:1154 184.23.23.61:7565 ESTABLISHED TCP 10.2.2.22:1154 184.23.23.61:7565 已建立

Here is the java client code which sends the request.这是发送请求的java客户端代码。

        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.每次几分钟后 [5-6 分钟] 它退出没有任何响应。

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.我假设您正在 telnet 到您尝试从 Java 连接的相同 IP 地址和端口。

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. telnet连接并且您的客户端似乎也连接的事实意味着服务器正在运行,并且它已经在正确的 IP/主机上创建了一个绑定的ServerSocket It is probably even calling accept properly.它甚至可能正确地调用accept 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.无论哪种方式,问题最有可能出现在服务器端......如果没有看到服务器端代码,我们无话可说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM