add tag
5 years ago Anonymous 1317

I am trying to open a TCP Client Connection to a remote server that is connected to an iOS device via WiFi.

I found some standard Objective-C Code to open a TCP connection at this StackOverflow question In my app’s info.plist file, I set the following properties:

Required device capabilities: Networking Features
Application uses WiFi : true

The remote server is a measuring device that has the IP address 192.168.0.1, and is a WiFi hotspot.

When my iPad was connected to 192.168.0.1, I set the Gateway on this device to 192.168.0.1 via its web interface.

On my iPad, I set a manual IP address of 192.168.0.2, and a subnet mask 255.255.255.0 for this WiFi connection. As far as I understand, this means the measuring device will accept a connect attempt from 192.168.0.2.

This manual IP address setting is a requirement by the way, which I can’t change, due to other requirements of myApp. The IP address must be fixed.

My code tries to get read and write streams for IP Address 192.168.0.1, port 80. It fails every time with the error message “Network is down”, despite the iPad showing a WLAN connection to the server (measuring device).

The iPad logs are below. As far as I can see from the log, the iPad is trying to connect over its (disabled) mobile connection, not the WiFi.

Is my guess correct, that it’s trying to connect over the wrong network, and if yes, then how can I force it to connect over WiFi to 192.168.0.1?

Top Answer
5 years ago Anonymous 1317

It turned out that there were two problems.

Firstly, it was not possible to telnet to the measuring device while the gateway was set to the device’s IP address. When I changed the gateway value to “0.0.0.0” on the measuring device, it was possible to telnet to the device.

An attempt to connect using my Objective-C code then resulted in kCFErrorDomainCFNetwork error 2.

This error code is associated with DNS problems. But my code passed an IP address to CFStreamCreatePairWithSocketToHost, not a URL. The code should not have been trying to make DNS lookup requests.

The problem lay in the NSString* parameter being passed as the address.

I changed the address parameter in the function call to this:

and it is accepted as a valid IP address.

5 years
Jack Douglas replying to Anonymous 1317 — Sunday, 21st Jun 2020 13:11

I’ll have a think about that — if we don’t set it up right now, I’ll make a note to migrate this over when we do 😃

3 hours
Anonymous 1317 — Sunday, 21st Jun 2020 10:05

I think the most valuable Thing in this Question is now the link between the error code and a badly formated Input Parameter. So yes, maybe objective-C if you do start a page for it.

Anonymous 1317 — Sunday, 21st Jun 2020 10:03

Any Problem involving Hardware and Network communications has so many potential Sources. I’m happy to have been able to narrow it down to my code in the end.

Anonymous 1317 — Sunday, 21st Jun 2020 10:00

😃 yes it was. But I only have one small file of Objective-C.

Jack Douglas — Sunday, 21st Jun 2020 09:56

Anonymous — 10 days ago in The Tavern

Hello, is there anywhere currently where I can ask an Objective-C Question? I’m not an Obj-C expert, so I don’t like to make a formal request for a site as I wouldn’t be able to contribute answers!

Jack Douglas — Sunday, 21st Jun 2020 09:56

oh wait that was actually from you 😃

Jack Douglas — Sunday, 21st Jun 2020 09:55

@Anonymous as it stands, would this question fit better in an Objective-C commnity do you think? We’ve had a request for one…

Jack Douglas — Sunday, 21st Jun 2020 09:50

a misconfigured gateway shouldn’t interfere with traffic on the local network

Jack Douglas — Sunday, 21st Jun 2020 09:50

in which case I don’t know

Jack Douglas — Sunday, 21st Jun 2020 09:49

oh wait, scratch that, it wasn’t telnet doing the dns

Jack Douglas replying to Anonymous 1317 — Sunday, 21st Jun 2020 09:49

probably because it was trying to do a DNS lookup that failed? Any DNS lookup is going to need a valid gateway to get out onto the internet…

32 minutes
Anonymous 1317 — Sunday, 21st Jun 2020 09:17

I don’t understand why I couldn’t Telnet when the gateway on the measuring device was set to the measuring device’s fixed IP address though.

Anonymous 1317 — Sunday, 21st Jun 2020 09:16

See answer 😃

12 minutes
Jack Douglas — Sunday, 21st Jun 2020 09:05

sounds like progress 😃

Anonymous 1317 — Sunday, 21st Jun 2020 09:02

I know why the telnet didn’t work now - the messages that I can use to test the measuring Device contain a non-standard character, and the keyboard properties of the telnetting app have to be changed to allow this character to be entered correctly.

2 days
Jack Douglas replying to Anonymous 1317 — Friday, 19th Jun 2020 19:45

don’t worry too much about that — we can either edit it into something useful for others, or leave it without an answer. Questions without answers here are unlikely to come up in search results.

Jack Douglas — Friday, 19th Jun 2020 19:43

with iTerminal, are you sure it is trying to telnet rather than ssh?

Jack Douglas — Friday, 19th Jun 2020 19:43

that’s interesting, and surprising

Jack Douglas — Friday, 19th Jun 2020 19:43

now I can Telnet from the mac, but not from any of the iPads using iTerminal or GetConsole

2 hours
Anonymous 1317 — Friday, 19th Jun 2020 17:38

I am now getting a lot of “try this” recommendations, in Reply to my email, presumably until something works, but nobody really understands how. Turns out the instructions I got before were not as solidly based on fact as I believed.

Anonymous 1317 — Friday, 19th Jun 2020 17:32

I’m not sure how useful this Question will be to others, but feel I ought to make it complete…

an hour
Anonymous 1317 — Friday, 19th Jun 2020 16:06

I changed the Gateway on the Server side to 0.0.0.0, and now I can Telnet from the mac, but not from any of the iPads using iTerminal or GetConsole. iTerminal appears to connect, and prompts me to close the Connection when I click “close”, but I can’t type in any commands. My own code still fails to connect with the same Network Down error.

40 minutes
Anonymous 1317 — Friday, 19th Jun 2020 15:26

Thank you very much for your explanations. The IP configuration makes more sense to me now than it did this morning. I still have no idea why it’s wrong though.

21 minutes
Anonymous 1317 — Friday, 19th Jun 2020 15:05

The Gateway is configured on the Server side, and the subnet mask on the client side, and I have used the correct IP address and port. Thank you for explaining the significance of the subnet mask by the way. I don’t understand how this configuration is wrong, especially as this is the configuration we were told to use. I have asked the supplier to clarify it.

Anonymous 1317 — Friday, 19th Jun 2020 15:00

Telnet seems to confirm the results that I got from my app code. So the connection must be wrongly configured.

21 minutes
Anonymous 1317 — Friday, 19th Jun 2020 14:39

Made a third attempt on a different iPad, with a WLAN connection to the measuring device, using GetConsole app to make a telnet connection to 192.168.0.1 port 80, and got a reply telling me to connect to the internet and that Connection isn’t possible without an Internet Connection.

17 minutes
Anonymous 1317 — Friday, 19th Jun 2020 14:23

However, on the Mac, when also connected to the measuring device, and with iTerminal closed on the iPad, I tried “Telnet 192.168.0.1 80” on the command line, and I get “Telnet: unable to connect to remote host. Operation timed out”

Anonymous 1317 — Friday, 19th Jun 2020 14:21

This is a Little odd. On the iPad, iTerminal Shows me no error message, and it goes to the “Connected” screeen and Shows me the keyboard, but I can’t type anything.

26 minutes
Anonymous 1317 — Friday, 19th Jun 2020 13:55

OK, I have connected via Telnet with iTerminal. It brings up the keyboard, but when I type, the letters aren’t echoed. Can’t find a setting About that.

Anonymous 1317 — Friday, 19th Jun 2020 13:54

I think it’s time for me to buy TCPIP Networking For Dummies 😦

an hour
Jack Douglas replying to Anonymous 1317 — Friday, 19th Jun 2020 13:09

no, the network is defined by the subnet mask not the gateway

26 minutes
Anonymous 1317 — Friday, 19th Jun 2020 12:43

It would have to see the gateway on the Server (measuring device) to know that they weren#t in that Network though?

Jack Douglas — Friday, 19th Jun 2020 12:34

ask yourself, “why would the iPad send TCP packets to 192.168.0.x that aren’t addressed to an IP address in that network”?

Jack Douglas — Friday, 19th Jun 2020 12:33

it will route to the correct network, or via a gateway defined on one of the iPad connections

Jack Douglas replying to Anonymous 1317 — Friday, 19th Jun 2020 12:32

the iPad will not route traffic on a different network over that connection

Anonymous 1317 — Friday, 19th Jun 2020 12:30

Why won’t the measuring device see the Connection?

Jack Douglas — Friday, 19th Jun 2020 12:30

If the app tries to access another IP address, it will be rejected by the measuring device, so it will Default back to the UMTS/LTE Connection.

If the app tries an address on a different network, it will not be rejected by the measuring device, because the measuring device will never see the connection. The connection will go directly via another route.

Jack Douglas — Friday, 19th Jun 2020 12:29

otherwise we just are speculating

Jack Douglas — Friday, 19th Jun 2020 12:29

that seems like it needs to be the first step

Jack Douglas — Friday, 19th Jun 2020 12:28

good — so if telnet can connect on port 80 we know there is a problem with the app

Anonymous 1317 — Friday, 19th Jun 2020 12:27

I set the IP and subnet filter on the iPad side

Anonymous 1317 — Friday, 19th Jun 2020 12:27

No, I set the gateway on the server side.

Jack Douglas — Friday, 19th Jun 2020 12:27

just the IP and subnet

Jack Douglas — Friday, 19th Jun 2020 12:27

don’t set the gateway on that connection

Jack Douglas — Friday, 19th Jun 2020 12:26

indeed

Anonymous 1317 — Friday, 19th Jun 2020 12:26

My app doesn’t make the IP connection. It should open TCP socket on an already opened IP connection

Anonymous 1317 — Friday, 19th Jun 2020 12:25

The TCP part of this WLAN connection is configured with “manual” and the IP address is set to 192.168.0.2

Jack Douglas replying to Anonymous 1317 — Friday, 19th Jun 2020 12:25

yes that is the ‘whole iPad’ though, not just ‘your app’

Anonymous 1317 — Friday, 19th Jun 2020 12:25

I make a Manual WLAN Connection to the measuring device with the iPad.

Jack Douglas — Friday, 19th Jun 2020 12:24

perhaps a silly question: what do you mean by “set a fixed IP address on the test app”? You can’t surely set an IP address on an app, only on a network interface?

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.