使用 ServerSocket 构建服务端

Android社区 收藏文章

Use ServerSocket.bind() to bind to an address and a port. Get the socket from the ServerSocket and listen to it for the data.

import 'dart:io';
import 'dart:convert';

main() async {
  var serverSocket = await ServerSocket.bind('127.0.0.1', 4041);
  print('connected');
  await for (var socket in serverSocket)
    socket.transform(UTF8.decoder).listen(print);
}
相关标签

扫一扫

在手机上阅读