Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] W/System.err: java.net.SocketException: socket failed: EACCES (Permission denied) in android

Posted on November 14, 2022

Solution 1 :

There’s a typo in the manifest: PROmission instead of PERmission!

<uses-permission android_name="android.promission.INTERNET"/>

should say

<uses-permission android_name="android.permission.INTERNET"/>

Solution 2 :

Your app is running on an emulator. If your app uses localhost address 127.0.0.1 it tries to connect to a server also running on that emulator.

If your server is running on the same pc your emulator is running on your app should use ip address 10.0.2.2 instead.

Problem :

Tying push the data from my application to local server.

 public class MainActivity extends AppCompatActivity {
 Socket socket;
 private static final String SERVER_IP = "127.0.0.1";//server ip

 private static final int SERVERPORT = 8000;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
new Thread(new ClientThread()).start();
}
private class ClientThread implements Runnable {
    @Override
    public void run() {

        try {
            InetAddress serverAddr = InetAddress.getByName(SERVER_IP);

            socket = new Socket(serverAddr, SERVERPORT);

        } catch (UnknownHostException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
}

In the manifest file I have registered below permissions

<uses-permission android_name="android.promission.INTERNET"/>
<uses-permission android_name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android_name="android.permission.ACCESS_WIFI_STATE"/> 

getting below error :

  W/System.err: java.net.SocketException: socket failed: EACCES (Permission denied)
  I/zygote: NativeAllocBackground concurrent copying GC freed 2066(637KB) AllocSpace 
  objects, 0(0B) LOS objects, 73% free, 547KB/2MB, paused 13.469ms total 130.017ms
  W/System.err:     at java.net.Socket.createImpl(Socket.java:487)
  W/System.err:     at java.net.Socket.<init>(Socket.java:441)
  W/System.err:     at java.net.Socket.<init>(Socket.java:248)
  W/System.err:     at com.abc.MainActivity$ClientThread.run(MainActivity.java:85)

Can you please help me to resolve this issue.

Comments

Comment posted by blackapps

Where is your server running? On the same Android device your app is running?

Comment posted by GNK

RSI Server is not mobile application . It is local server and running in my laptop.

Comment posted by einUsername

I’m assuming you are running this on the emulator. The emulator and the PC are like seperate devices. I don’t think you can connect to the same pc through 127.0.0.1. I had a similar issue once and running it on a real phone and connecting through the local network fixed it.

READ  [ANSWERED] android - Is blockingget safe to use in background thread
Powered by Inline Related Posts

Comment posted by GNK

yes , I am running in emulator. I found local-dev.yaml file in the local RSI server. This file contains http: port: 8080 bindAddress: 127.0.0.1 rsi: basepath: “/rsi/v0” obd: port: 4000 bindAddress: 127.0.0.1

Comment posted by 127.0.0.1:8080

Sorry I could not able to understand.I need to change ip in android code ? I just inform to you I can able to see response of

Comment posted by blackapps

I do not believe you can use 127.0.0.1 in a browser running in the emulator to connect with a server running on the pc where the rmulator runs.

Comment posted by GNK

1|generic_x86:/ $ ifconfig lo Link encap:UNSPEC inet addr:127.0.0.1 Mask:255.0.0.0

Comment posted by GNK

If I want test in mobile , which IP need to set?

Comment posted by blackapps

Using wifi: To the ip of the device where your server is running on.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress