Fllutter&Dart,当我尝试发送UDP数据包时,模拟器的屏幕被关闭时,发送失败。好的。 谜团是我无法以任何方式抓住失败。 UDP套接字Send()不是异步,因此尝试&捕获是正确的。如果我添加等待,什么都不会改变。如果我尝试附加.catcherror,则不允许使用它,因为它不是异步方法。
try {
print(_udpSocket.toString()); //It prints Instance of '_RawDatagramSocket'
_udpSocket!.send(_packet,_serverAddress!,Server_UdpPort); //Send packet
} catch (exception) {
print("aaaaaaaaaaaa"); //It never prints aaaaa, it never executes this code
print(exception.toString());
}
Console中的Error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Send failed (OS Error: Operation not permitted, errno = 1), address = 0.0.0.0, port = 0
E/flutter (25939): #0 _NativeSocket.send (dart:io-patch/socket_patch.dart:1213:34)
E/flutter (25939): #1 _RawDatagramSocket.send (dart:io-patch/socket_patch.dart:2460:15)
E/flutter (25939): #2 ClassServerConnection._handleOutcomingUdpStreamPacketsQueueEvent_async (package:meet2/2_1_4_ClassServerConnection.dart:1129:29)
E/flutter (25939): #3 ClassServerConnection._handleOutcomingUdpStreamPackets.<anonymous closure> (package:meet2/2_1_4_ClassServerConnection.dart:1090:93)
E/flutter (25939): #4 ClassQueue.callEvent.<anonymous closure> (package:meet2/2_1_2_ClassQueue.dart:78:68)
E/flutter (25939): #5 new Future.delayed.<anonymous closure> (dart:async/future.dart:424:39)
E/flutter (25939): #6 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (25939): #7 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (25939): #8 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (25939): #9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
WLAN断开连接时,使用MDNS_DART存在完全相同的问题。我无法抓住例外。有消息吗?