Last active
August 29, 2015 14:17
-
-
Save kgersen/40fc031bf045387a6045 to your computer and use it in GitHub Desktop.
dart remoteAddress bug on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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