Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to bind the socket to a port less than 1024 #45

Closed
VijayLogitech opened this issue Apr 21, 2017 · 3 comments
Closed

Not able to bind the socket to a port less than 1024 #45

VijayLogitech opened this issue Apr 21, 2017 · 3 comments
Labels

Comments

@VijayLogitech
Copy link

i am trying to convert my native app, to react-native for code sharing between android and ios. in my application, i use react-native-udp to detect the devices connected to the wifi. In my native application, i bind to a port 137, to detect a specfic type of device. When i try to recreate the same in react-native-udp, during bind, 137 it gives me error "EACCESS". the only difference i see from the native application code and react native udp code is, native application uses DatagramSockets(), where as react-native-udp is using MulticastSocket().
//new MulticastSocket(port);
Can you please make it work for binding to a port less than 1024?

@mvayngrib
Copy link
Member

@VijayLogitech does it work when you use a MulticastSocket natively (not via react-native-udp -> GCDAsyncUdpSocket)?

@VijayLogitech
Copy link
Author

@mvayngrib hi, sorry for the late reply, need ur help here.
i tried with multicastSocket natively to bind to port 137, and it gives the same EACCESS error which we get in react native. So multigram socket is not working for port 137 both in RN and natively.
Also the ip range supported in Multicast socket address range only 224.0.0.0 to 239.255.255.255.
So, i suggest having datagramsocket, for ip's outside the multicast socket address, as well as port number less than 1024.
will it be possible for you to change the instance creation to Datagramsocket, only if the port range is less than 1024, in the below line.

filename : android/src/main/java/com/tradle/react/UdpSocketClient.javaandroid/src/main/java/com/tradle/react/UdpSocketClient.java

public void bind(Integer port, @nullable String address) throws IOException {
if(port <1024)
mSocket = new DatagramSocket(null);

@Rapsssito
Copy link
Collaborator

To bind to a port less than 1024, you need to be root. On Android, there are two ways of doing that: being System app or su binary. (More info on this StackOverflow answer).

@Rapsssito Rapsssito changed the title Not able to bind the socket to a port less than 1024, but it is acomplished in native applications Not able to bind the socket to a port less than 1024 May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants