class FindPage extends StatefulWidget {
  const FindPage({super.key});
  @override
  State<StatefulWidget> createState() => _FindPage();
}

class _FindPage extends State<FindPage> {
  RawDatagramSocket? _socket;
  @override
  void initState() {
    super.initState();
    RawDatagramSocket.bind(InternetAddress.anyIPv4, 10808).then((socket) {
      _socket = socket;

      socket.broadcastEnabled = true;
      print('${socket.address.address}:${socket.port}');
      socket.listen((RawSocketEvent e) {
        Datagram? d = socket.receive();
        if (d == null) return;
        var message = String.fromCharCodes(d.data);
        print(message);
      });
    });

  }

  @override
  void dispose() {
    super.dispose();
    _socket?.close();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('查找设备'),
      )
    );
  }
}