0

I have a Java based server using JmDNS which is being discovered from an iOS app.

The discovery works fine and this is the callback that gets executed by the NetServiceDelegate to record the details:

public func netServiceDidResolveAddress(_ service: NetService) {
    guard let hostName = service.hostName else {
        return
    }

    mockServerUrl = "http://\(hostName):\(service.port)/analytics"
    Logger.log("Using mock server at \(mockServerUrl)", forLevel: .info)
}

This results in a URL that looks like this: http://az-mbp-ether-lan.local.:9090

Now I swear this was working, however now when I try and send data to this endpoint with Alamofire it consistently times out.

Replacing the hostname with the hardcoded IP address of the target machine makes it work again, so there is no fundamental issue with the code sending the data.

Should an address of the form above ending in ".local." be resolvable from an iOS device on the same network as the target server?

zorro2b
  • 2,227
  • 4
  • 28
  • 45
  • The delegate method `netServiceDidResolveAddres` is for resolving the IPv4 and IPv6 addresses. It has no effect regarding the hostname which does not change after `didFindService`. – vadian Mar 01 '17 at 09:53
  • When I inspected the address that came back in the addresses field I found that it was "127.0.0.1" which seems useless for connection from the phone to the server. – zorro2b Mar 01 '17 at 21:37
  • You have to extract the IPV4 or IPv6 addresses from the `addresses` array in the `netServiceDidResolveAddress` method which is an array of `(NS)Data` objects containing `struct sockaddr` objects. – vadian Mar 01 '17 at 21:41
  • Yes, I did. The only address that came back in the addresses field was "127.0.0.1" :( – zorro2b Mar 01 '17 at 21:52

1 Answers1

0

The problem was on the Java server side. It was registering by calling InetAddress.getLocalHost(). This was returning the loopback address.

I revised my code to find a non-loopback address based on this question: IP Address not obtained in java

Community
  • 1
  • 1
zorro2b
  • 2,227
  • 4
  • 28
  • 45