使用UNIX套接字与Dart

6

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

final socket = await Socket.connect('127.0.0.1', 8888);

我想使用一个UNIX 域套接字,有没有方法可以在 Dart 中实现?

1个回答

11

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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接