使用 ServerSocket 构建服务端

2138次阅读  |  发布于5年以前

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

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8