Skip to content

Instantly share code, notes, and snippets.

@kgersen
Last active August 29, 2015 14:17
Show Gist options
  • Save kgersen/40fc031bf045387a6045 to your computer and use it in GitHub Desktop.
Save kgersen/40fc031bf045387a6045 to your computer and use it in GitHub Desktop.
dart remoteAddress bug on Windows
import "dart:io";
import 'dart:convert' show UTF8;
// client, pass the url as parameter:
// dart client.dart http://localhost:8192
void main(List<String> args) {
HttpClient client = new HttpClient();
client.getUrl(
Uri.parse(args[0])).then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
// Process the response.
response.transform(UTF8.decoder).listen((contents) {
print(contents.toString());
}, onDone: () => client.close());
});
}
import 'dart:io';
void main() {
HttpServer.bind(InternetAddress.ANY_IP_V6, 8192).then((server) {
server.listen((HttpRequest request) {
String client_host = request.connectionInfo.remoteAddress.host;
String client_addr = request.connectionInfo.remoteAddress.address;
request.response.write("hello you are: $client_host at $client_addr");
print("http connection from: $client_host at $client_addr");
request.response.close();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment