Socket operation not permitted
What's inside this article
⌄
- Socket operation not permitted error
- Socketexception permission denied
- Fix socket permission error
- Socket operation error solution
We may run into this error while developing an app for Android:
Connection error: java.net.SocketException: socket failed: EPERM (Operation not permitted)
at java.net.Socket.createImpl(Socket.java:517)
at java.net.Socket.getImpl(Socket.java:577)
at java.net.Socket.setSoTimeout(Socket.java:1203)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:293)
It may look like this as well:
Connection error: java.net.SocketException: Operation not permitted
at sun.nio.ch.Net.socket0(Native Method)
at sun.nio.ch.Net.socket(Net.java:420)
at sun.nio.ch.Net.socket(Net.java:413)
at sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:130)
I won’t be torturing you with long explanations and references 😁, so everything you should do is to check that you have android.permission.INTERNET permission in your AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application>
</application>
</manifest>
Sometimes it’s necessary to add android.permission.ACCESS_NETWORK_STATE as well.