目前我可以使用TCP套接字:
final socket = await Socket.connect('127.0.0.1', 8888);
我想使用UNIX socket。有没有办法用Dart做到这一点?
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);