使用 ServerSocket 构建服务端

使用 ServerSocket 构建服务端

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);
}

手机扫码阅读