Skip to content

Instantly share code, notes, and snippets.

@selvan
Created June 9, 2020 16:31
Show Gist options
  • Save selvan/981526b6c62459045aab5e98bc132507 to your computer and use it in GitHub Desktop.
Save selvan/981526b6c62459045aab5e98bc132507 to your computer and use it in GitHub Desktop.
Dart - Unix Domain Socket
// 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