Created
March 28, 2014 16:11
-
-
Save zero-master/9836498 to your computer and use it in GitHub Desktop.
Ping-Pong Server Socket-Socket Client implemetation for Dartlang.
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: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