Skip to content

Instantly share code, notes, and snippets.

@zero-master
Created March 28, 2014 16:11
Show Gist options
  • Save zero-master/9836498 to your computer and use it in GitHub Desktop.
Save zero-master/9836498 to your computer and use it in GitHub Desktop.
Ping-Pong Server Socket-Socket Client implemetation for Dartlang.
import 'dart:io';
import 'dart:async';
main() {
ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 8000).then((s_server) {
s_server.listen((socket) {
socket.write('Ping!');
socket.listen((data){
print(new String.fromCharCodes(data));
sleep(new Duration(seconds:1));
socket.write('Ping!');
});
});
}).then((_) {
Socket.connect(InternetAddress.LOOPBACK_IP_V4, 8000).then((c_socket) {
c_socket.listen((data){
print(new String.fromCharCodes(data));
sleep(new Duration(seconds:1));
c_socket.write('Pong!');
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment