您好,我是 linux 和 android 编程的新手,我的想法是通过 TCP 套接字将数据包数据从 Raspberry Pi 发送到 Android 手机。.当连接开始时,数据流很好,在发送少量数据后,流有时会“卡住”。
我的安卓手机 IP 192.168.43.1 我的静态树莓 IP 192.168.43.5
我尝试更改端口号但连接仍然卡住,我尝试减小数据包数据的大小但仍然卡住。我认为树莓防火墙(如果存在)是问题或者可能是 iptables 配置,但是如何检查并禁用树莓防火墙?只是信息,在我的覆盆子中没有引火器。或者如何使用 iptables ?
你能帮我解释为什么会这样吗?或者任何参考都会很棒,在此先感谢!这是我的日志:
07-30 13:11:20.731: W/System.err(13264): java.net.ConnectException: failed to connect to /192.168.43.20 (port 12345): connect failed: ECONNREFUSED (Connection refused)
07-30 13:11:20.731: W/System.err(13264): at libcore.io.IoBridge.connect(IoBridge.java:118)
07-30 13:11:20.731: W/System.err(13264): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
07-30 13:11:20.731: W/System.err(13264): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
07-30 13:11:20.731: W/System.err(13264): at java.net.Socket.startupSocket(Socket.java:571)
07-30 13:11:20.731: W/System.err(13264): at java.net.Socket.tryAllAddresses(Socket.java:132)
07-30 13:11:20.731: W/System.err(13264): at java.net.Socket.<init>(Socket.java:182)
07-30 13:11:20.731: W/System.err(13264): at java.net.Socket.<init>(Socket.java:154)
07-30 13:11:20.731: W/System.err(13264): at com.uavgama.Streamingdata.Masukan(Streamingdata.java:19)
07-30 13:11:20.731: W/System.err(13264): at com.uavgama.Adhrsparse.Keluar(Adhrsparse.java:71)
07-30 13:11:20.731: W/System.err(13264): at com.uavgama.Adhrsparse$1.run(Adhrsparse.java:26)
07-30 13:11:20.731: W/System.err(13264): at android.os.Handler.handleCallback(Handler.java:615)
07-30 13:11:20.731: W/System.err(13264): at android.os.Handler.dispatchMessage(Handler.java:92)
07-30 13:11:20.731: W/System.err(13264): at android.os.Looper.loop(Looper.java:137)
07-30 13:11:20.731: W/System.err(13264): at android.app.ActivityThread.main(ActivityThread.java:4744)
07-30 13:11:20.731: W/System.err(13264): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 13:11:20.741: W/System.err(13264): at java.lang.reflect.Method.invoke(Method.java:511)
07-30 13:11:20.741: W/System.err(13264): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-30 13:11:20.741: W/System.err(13264): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-30 13:11:20.741: W/System.err(13264): at dalvik.system.NativeStart.main(Native Method)
07-30 13:11:20.741: W/System.err(13264): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
07-30 13:11:20.741: W/System.err(13264): at libcore.io.Posix.connect(Native Method)
07-30 13:11:20.741: W/System.err(13264): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
07-30 13:11:20.741: W/System.err(13264): at libcore.io.IoBridge.connectErrno(IoBridge.java:131)
07-30 13:11:20.741: W/System.err(13264): at libcore.io.IoBridge.connect(IoBridge.java:116)
07-30 13:11:20.741: W/System.err(13264): ... 18 more
这是我用来发送的打包数据:
$909.29|34.16|160.39907|123.51508|189.56|40.42|339.78#
$62.88|52.38|32.62654|170.11087|19.19|99.57|127.72#
$847.45|65.29|128.59294|114.23773|161.92|268.55|28.90#
$957.35|48.49|142.63874|9.20948|161.73|297.63|348.33#
$634.97|25.16|105.1316|23.51827|185.56|195.88|189.1#
format :
$altitude|airspeed|lat|lon|pitch|roll|yaw#
这是用于发送数据的树莓 bash 代码
cat /home/pi/file | awk -F'\t' 'END{print}' | nc -l 12345
这是我用于数据流的java代码:
public static String Masukan() {
try {
Socket s;
s = new Socket("192.168.43.20", 12345);
s.getReuseAddress();
s.getTcpNoDelay();
BufferedReader inp = null;
inp = new BufferedReader(new InputStreamReader(s.getInputStream()));
String serverMsg = null;
serverMsg = inp.readLine();
if ( serverMsg.endsWith("#")) {
filter = serverMsg;
s.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return filter;
};