Skip to content

Instantly share code, notes, and snippets.

@RANUX
Forked from mgechev/basic-tcp-server.dart
Created February 12, 2020 08:16
Show Gist options
  • Save RANUX/eda8eb868684f1ff87d17087d1ba1a9b to your computer and use it in GitHub Desktop.
Save RANUX/eda8eb868684f1ff87d17087d1ba1a9b to your computer and use it in GitHub Desktop.
Basic TCP server in Dart
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