socket failed: EACCES (Permission denied)

Asked

Viewed 207 times

1

He was creating an Android project that makes him communicate with a Windows machine through Sockets, being the machine the server, and the mobile device (Samsung Galaxy S3 MINI) the client.

I created a wireless hosted network on the computer, and connected the device on the pc via USB cable, but connected the wireless network I created on the computer.

I made that when there was an error, the error is written in a Textview, and returned the error:

socket failed: EACCES (Permission Denied)

Activity Code: http://pastebin.com/rw9rzE9P

Manifest.xml http://pastebin.com/bxaDaubx

1 answer

2

There are some details in your code.

On the manifest, the line

<permission  android:name="android.permission.INTERNET"/>

Should be

<uses-permission android:name="android.permission.INTERNET" />

Regarding the code of Activity, when creating a class instance Socket, you are creating a TCP/IP connection with any destination, which in the case of your code is the mobile itself:

socket = new Socket("127.0.0.1",5000);

The IP 127.0.0.1, refers to the machine/device itself (is the IP of loopback), that is, you would not be connecting to the computer in this way. You should replace this IP with the IP of your computer.

Also, you must ensure that there is some program/service on the computer, "listening" on port 5000, otherwise the connection will also fail.

  • This 127.0.0.1 was a way to 'hide' my IP, I typed ipconfig to get the IP of the connection I’m sharing with the phone, I’m connected to a Wifi that provides the internet, and the other I share the internet, in case what I connect with the device on the machine with the network "Wireless Network Connection 2", I must take the IP of that network that I share with the device?

  • OK! But, in an example, I would put something like "X.X.X.X", or even "..." ;) Yes, you must use the IP of the network where the phone is. Now, there is a service running on the machine, listening on the port 5000 of this IP?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.