nibbo
nibbo

Reputation: 189

Flutter SocketException: Failed host lookup: 'xxxxxx.local'

I have a raspberry pi in my lan with the hostname 'xxx.local'. My phone is connected to the wifi but everytime I try to fetch data from my REST backend using the '.local' address i get this exception:

'SocketException (SocketException: Failed host lookup: 'xxx.local' (OS Error: No address associated with hostname, errno = 7))'

But it works fine when I try to connect to it via ssh or even when I try to fetch data using postman.

Is it possible that it has something to do with the mobile data, since it is deactivated because my test phone has no sim card inside. If yes, would it be possible to work without sim card?

The code where I try to fetch the data:

static Future<List<Device>> fetchDevices() async {
final response = await http.get('http://test-hub.local:9080/devices');

if (response.statusCode == 200) {
  final data = json.decode(response.body);
  print(data);
  List<Device> responses =
      data.map<Device>((j) => Device.fromJson(j)).toList();
  print(responses);
  return responses;
} else {
  throw Exception(
      'Failed to load Devices: ${response.statusCode} [${response.reasonPhrase}]');
}
}

Upvotes: 2

Views: 734

Answers (1)

cas
cas

Reputation: 817

I got stuck on this for a long time, The issue is that Android currently does not support mdns lookups (.local).

I don't know how you are getting your mdns address, but for people using the multicast_dns package you can fetch the ip address as described here. Then you can use the IP address for your http queries

Upvotes: 1

Related Questions