Issue with SwiftNIO connect-proxy in iOS app


I am very new to networking with Swift, so I greatly appreciate anyone who can assist me here. I'm trying to get a basic proxy server working on an iOS device, using the code found at the SwiftNIO official example.. On the command line, it works great! However, I have been unable to successfully connect to the server when running on my phone (not a simulator). My phone and computer are on the same network.

In the Xcode console, it logs that is it is successfully listening on the designated ports:

2022-06-21T13:16:44-0400 info : [NetworkTests] Listening on Optional([IPv6]::1/::1:8080)
2022-06-21T13:16:44-0400 info : [NetworkTests] Listening on Optional([IPv4]

But when I attempt to connect to it using curl -v -x http://[my phone's 172.20 ip]:8080, I receive the following error message in my Mac terminal:

*   Trying 172.[ip]:8080...
* connect to 127.[ip] port 8080 failed: Connection refused
*   Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
* Failed to connect to localhost port 8080 after 14 ms: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 8080 after 14 ms: Connection refused

Thank you to anyone who can offer any advice. I''m happy to clarify anything!

Not really a SwiftNIO expert here — too many APIs, too little time — but the log suggests that your server is listening on the loopback address ( for IPv4, ::1 for IPv6). If that’s the case, you won’t be able to connect to it from a different machine. If you want that to work, standard practice is to listen on the any address. In BSD Sockets this is INADDR_ANY and in6addr_any. Not sure how to get that from NIO.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

You can use when doing the bind.