socket
Posted pythonclub
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了socket相关的知识,希望对你有一定的参考价值。
server
import ‘dart:io‘; import ‘dart:convert‘; main(List<String> arguments) { //绑定地址和端口,获取套接字,监听每个连接 ServerSocket.bind(‘127.0.0.1‘, 8089).then((serverSocket) { print(‘开始监听‘); serverSocket.listen((socket) { socket.transform(utf8.decoder).listen(print); // socket.remoteAddress socket.write(‘from server‘); print(socket.remoteAddress); }); }); }
client
import ‘dart:io‘; main(List<String> arguments) { //创建一个Socket连接到指定地址与端口 Socket.connect(‘127.0.0.1‘, 8089).then((socket) { //输出socket运行时的类型 print(socket.runtimeType); socket.write(‘Hello, World!‘); }); }
以上是关于socket的主要内容,如果未能解决你的问题,请参考以下文章