We have a Dart wrapper around the socket APIs - `tcp.dart`. We might want to look at using it here, to reduce the amount of code and simplify the error handling.