在 Dart 中使用 UNIX 套接字

Aug*_*n R 1 unix-socket dart

目前我可以使用 TCP 套接字:

final socket = await Socket.connect('127.0.0.1', 8888);
Run Code Online (Sandbox Code Playgroud)

我想使用UNIX 套接字。有没有办法用 Dart 做到这一点?

Aug*_*n R 5

Dart 2.7.2 支持 UNIX 套接字(请参阅此 pr此问题)。

您需要使用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);
Run Code Online (Sandbox Code Playgroud)