目前我可以使用TCP套接字:
final socket = await Socket.connect('127.0.0.1', 8888);
我想使用一个UNIX 域套接字,有没有方法可以在 Dart 中实现?
目前我可以使用TCP套接字:
final socket = await Socket.connect('127.0.0.1', 8888);
我想使用一个UNIX 域套接字,有没有方法可以在 Dart 中实现?
UNIX sockets在Dart 2.7.2中得到支持(请参见此pull request或此问题)。
您需要使用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);