I’m trying to write an app that uses TCP/IP to communicate to and from an iPhone. To test the basic calls, I was trying to open port 7 (which supposedly is set up to echo any input back to the receiver), write to it, and read the results.
My code works after a fashion. I can, for example, open a site using “www.xxx.com” for a host name and port 80, write an http address, and get back a response.
The problem is that I get an error, “The operation couldn’t be completed. Connection refused” error when trying to access port 7, and presumably any other port that isn’t opened by Apple for a specific purpose. I’ve opened port 7 on the AirPort WiFi router using the AirPort Utility app, and tried opening and writing to port 7 both on my Mac and on the iPad using their respective IP addresses from iOS, and always get the same error.
What needs to be done to open ports so I can use TCP/IP to communicate using iOS, either to other iOS devices or with a desktop computer? Or is using port 7 as a test simply not the way to go?
This question was answered by some kind folks on the Apple Developer forms. To summarize:
There is no supported way to use an echo service on iOS. The only way to test TCP/IP turns out to be to create a connection to an actual server. The development Mac can be used for that using, for example, netcat.