i get the following Exception
I/System.out: java.net.SocketException: socket failed: EACCES (Permission denied)
I have a closed network without internet access, only router, android device and raspberry pi.
My AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
i have only one Activity MainActivity:
public class MainActivity extends Activity {
private static final int PORT= 8888;
private static final int TIMEOUT_MS = 500;
@Override
protected void onCreate(Bundle savedInstanceState) {
final TextView tView;
Button buttonRed, buttonGreen, buttonBlue, buttonWhite;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tView = (TextView) findViewById(R.id.showroom_welcome);
buttonRed = (Button) findViewById(R.id.buttonred);
buttonRed.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
/*send message xyz*/
try {
String message = "\"xyz\"";
DatagramSocket socket = new DatagramSocket(PORT);
socket.setBroadcast(true);
socket.setSoTimeout(TIMEOUT_MS);
DatagramPacket packet = new DatagramPacket(message.getBytes(), message.length(), getBroadcastAddress(), PORT); //InetAddress.getByName("192.168.100.255"), PORT );
socket.send(packet);
}catch(UnsupportedEncodingException uee){
tView.setText(uee.getMessage());
System.out.println(uee.getMessage());
}catch (SocketException se){
tView.setText(se.getMessage() );
System.out.println(se+"\n");
}catch (IOException ioe){
tView.setText(ioe.getMessage());
System.out.println(ioe + "\n");
}
}
});
}
It is a UDP client that sends only xyz to raspi. Do you have an idea what is the problem?