【发布时间】:2020-06-22 15:50:55
【问题描述】:
目前我可以使用 TCP 套接字:
final socket = await Socket.connect('127.0.0.1', 8888);
我想使用UNIX socket。 有没有办法用 Dart 做到这一点?
【问题讨论】:
标签: dart unix-socket
目前我可以使用 TCP 套接字:
final socket = await Socket.connect('127.0.0.1', 8888);
我想使用UNIX socket。 有没有办法用 Dart 做到这一点?
【问题讨论】:
标签: dart unix-socket
Dart 2.7.2 支持 UNIX 套接字(请参阅 this pr 或 this issue)。
您需要使用InternetAddress 构造函数并将可选参数type 设置为unix:
import 'dart:io';
...
// With String address
final host = InternetAddress(address, type: InternetAddressType.unix);
// OR with UInt8List raw address
final host = InternetAddress.fromRawAddress(rawAddress, type: InternetAddressType.unix);
final socket = await Socket.connect(host, port);
【讨论】: