-
-
Save nobuh/2757a7853961807d6de833124c56665a to your computer and use it in GitHub Desktop.
Basic TCP server in Dart
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:core'; | |
import 'dart:async'; | |
import 'dart:io'; | |
void startServer() { | |
Future<ServerSocket> serverFuture = ServerSocket.bind('0.0.0.0', 55555); | |
serverFuture.then((ServerSocket server) { | |
server.listen((Socket socket) { | |
socket.listen((List<int> data) { | |
String result = new String.fromCharCodes(data); | |
print(result.substring(0, result.length - 1)); | |
}); | |
}); | |
}); | |
} | |
void main() { | |
startServer(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment