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

TCP server on iOS only listens on the loopback address #99

Open
jjv360 opened this issue Feb 21, 2019 · 0 comments
Open

TCP server on iOS only listens on the loopback address #99

jjv360 opened this issue Feb 21, 2019 · 0 comments

Comments

@jjv360
Copy link

jjv360 commented Feb 21, 2019

Hi, when trying to create a TCP server with this code:

server.listen({ port: 1234, host: '0.0.0.0' })

... it ends up rejecting all connections from other devices. I also tried leaving out the host option, but there's a default of 0.0.0.0 in TcpServer.js:70 so it's the same result...

Looking at the native code, this line here converts the address 0.0.0.0 to localhost which seems wrong , since localhost would prevent outside connections... If I change it to null rather, it works correctly, same as on android...

// GCDAsyncSocket doesn't recognize 0.0.0.0
if ([@"0.0.0.0" isEqualToString: host]) {
host = @"localhost";
}

... change to ...

 if ([@"0.0.0.0" isEqualToString: host]) { 
     host = nil; 
 } 

Using nil seems correct, since the headers for CocoaAsyncSocket say this:

The interface may be specified by name (e.g. "en1" or "lo0") or by IP address (e.g. "192.168.4.34").
You may also use the special strings "localhost" or "loopback" to specify that
the socket only accept connections from the local machine.

To accept connections on any interface pass nil, or simply use the acceptOnPort:error: method.

This is probably also the cause of these other related issues: #78 #72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant