Android Raspberry pi W/System.err(13264): java.net.ConnectException connection refused-Collection of common programming errors
Hello im new in linux and android programming , my idea is send packet data from Raspberry Pi to Android Phone via TCP socket. .When connection started, the data stream well , after few data sent the streaming sometimes “jammed”.
My android phone IP 192.168.43.1 My static Raspberry IP 192.168.43.5
I try to change the port number but the connection still jammed, I try to reduce the size of the packet data but also still jammed .I assume the raspberry firewall (if it exist) is the problem Or maybe the iptables configuration, but how to check and disable the Raspberry firewall? just info ,in my raspberry didn’t have firestarter. Or how to use the iptables ?
Could you help me why thats happen?or any reference would be great , thanks in advance! Here is my logcat :
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.(Socket.java:182)
07-30 13:11:20.731: W/System.err(13264): at java.net.Socket.(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
Here is the packed data i used to sent :
$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#
this is the raspberry bash code for send the data
cat /home/pi/file | awk -F'\t' 'END{print}' | nc -l 12345
Here is my java code for data streaming:
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;
};