mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:01:20 +00:00
b3df0a4bd5
Closes https://github.com/dart-lang/sdk/pull/50863 GitOrigin-RevId: e514be37c7f3b48cbce1048c359df00be7d2b18a Change-Id: I45ad308db60a5935f18a877f5480874acfef0efd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/277780 Reviewed-by: Alexander Thomas <athom@google.com>
61 lines
2 KiB
Dart
61 lines
2 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
import 'package:async_helper/async_helper.dart';
|
|
import 'package:expect/expect.dart';
|
|
|
|
void main() {
|
|
// A virtual tun/tap interface should be created with following instructions:
|
|
// Create an interface with name [tap0],
|
|
// sudo ip tuntap add name [tap0] mode tap
|
|
// Assign an ipv6 address [fe80:1::1],
|
|
// sudo ip -6 addr add dev [tap0] [fe80:1::1] scope link nodad
|
|
// Check for virtual interface with ipv6 set,
|
|
// ip address show
|
|
asyncStart();
|
|
try {
|
|
// Make sure the address here is the same as what it shows in
|
|
// "ip address show"
|
|
var ipv6 = 'fe80:1::1%tap0';
|
|
|
|
// Parses a Link-local address on Linux and Windows will throw an exception.
|
|
InternetAddress(ipv6);
|
|
|
|
HttpServer.bind(ipv6, 0).then((server) {
|
|
server.listen((request) {
|
|
var timer = new Timer.periodic(const Duration(milliseconds: 0), (_) {
|
|
request.response
|
|
.write('data:${new DateTime.now().millisecondsSinceEpoch}\n\n');
|
|
});
|
|
request.response.done.whenComplete(() {
|
|
timer.cancel();
|
|
}).catchError((_) {});
|
|
});
|
|
|
|
var client = new HttpClient();
|
|
client
|
|
.getUrl(Uri.parse("http://[${ipv6}]:${server.port}"))
|
|
.then((request) => request.close())
|
|
.then((response) {
|
|
print(
|
|
'response: status code: ${response.statusCode}, reason: ${response.reasonPhrase}');
|
|
int bytes = 0;
|
|
response.listen((data) {
|
|
bytes += data.length;
|
|
if (bytes > 100) {
|
|
client.close(force: true);
|
|
}
|
|
}, onError: (error) {
|
|
server.close();
|
|
});
|
|
});
|
|
asyncEnd();
|
|
});
|
|
} catch (e) {
|
|
Expect.fail('SocketException: $e');
|
|
asyncEnd();
|
|
}
|
|
}
|