我试图通过 telnet 向我的计算机发送命令,然后在使用 telnet 时将命令发送到串行端口
adb shell
$telnet 172.20.104.203 5334
$h
它从命令h返回数据,但是当我尝试使用android执行此操作时,它连接到套接字,我可以在计算机上看到它,它发送命令但是一旦它记录它已经发送它就会挂起并提出“应用程序没有响应”,它有等待或强制关闭,如果我等待它就保持不变。
这是我的 telnet 部分代码
private static final int TCP_SERVER_PORT = 5334;
private void runTcpClient() {
try {
Socket s = new Socket("172.20.104.203", TCP_SERVER_PORT);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
//send output msg
String outMsg = "$getPos";
out.write(outMsg);
out.flush();
Log.i("TcpClient", "sent: " + outMsg);
//accept server response
String inMsg = in.readLine() + System.getProperty("line.separator");
Log.i("TcpClient", "received: " + inMsg);
//close connection
s.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
它记录了发送,但它从不记录接收,我认为这可能与接收到的数据量有关,所以我只是发送了
$getPos
相反,但它仍然挂起。
有人知道会发生什么吗?