So I made a simple UDP Client for android, and for some reason it doesn't want to work. I've been struggling with this for like 5 hours now, and I can't find the problem. I even looked almost all the tutorials on the internet, to compare the codes, but I had no luck.
String serverString = "192.168.1.109";
int port = 7777;
Log.d("adam", "Debug");
DatagramSocket socket = null ;
String msg = "Hello World!";
try {
socket = new DatagramSocket() ;
InetAddress host = InetAddress.getByName(serverString);
byte [] data = msg.getBytes() ;
DatagramPacket packet = new DatagramPacket( data, data.length, host, port );
Log.d("adam", "Debug2");
socket.send(packet) ;
Log.d("adam", "Packet sent" );
} catch( Exception e )
{
Log.d("adam", "Exception");
Log.e("adam", Log.getStackTraceString(e));
}
finally
{
if( socket != null ) {
socket.close();
}
}
My mainfest:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Here is the debug img:
As you can see the "Packet sent" text is not in the logcat. So the problem is probably with the send()
function. Any idea what could be the problem?