How can I find an unused TCP port in Dart?
I'll add my 'hack' as an answer because I can't think of another way, and it seems to work pretty well.
Here's my getUnusedPort()
function:
import 'dart:io';
Future<int> getUnusedPort(InternetAddress address) {
return ServerSocket.bind(address ?? InternetAddress.anyIPv4, 0).then((socket) {
var port = socket.port;
socket.close();
return port;
});
}