Created
June 9, 2020 16:31
-
-
Save selvan/981526b6c62459045aab5e98bc132507 to your computer and use it in GitHub Desktop.
Dart - Unix Domain Socket
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
// Based on https://dart-review.googlesource.com/c/sdk/+/125932/34/tests/standalone_2/io/unix_socket_test.dart | |
import 'dart:async'; | |
import 'dart:io'; | |
Future<void> main() async { | |
var address = InternetAddress('/tmp/socket', type: InternetAddressType.unix); | |
var server = await ServerSocket.bind(address, 0, shared: true); | |
server.listen((client) async { | |
client.listen((data) { | |
print(new String.fromCharCodes(data).trim()); | |
client.write("Hello from simple server!\n"); | |
client.close(); | |
}, | |
onError: (error, StackTrace trace){ | |
print(error); | |
}, | |
onDone: () { | |
print("On Done.."); | |
}, | |
cancelOnError: false | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment