使用带有Dart的UNIX套接字

问题描述 投票:0回答:1

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

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

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

dart unix-socket
1个回答
3
投票

Dart 2.7.2支持UNIX套接字(请参阅this prthis 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);
© www.soinside.com 2019 - 2024. All rights reserved.