使用带有Dart的UNIX套接字

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用带有Dart的UNIX套接字相关的知识,希望对你有一定的参考价值。

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

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

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

答案

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

以上是关于使用带有Dart的UNIX套接字的主要内容,如果未能解决你的问题,请参考以下文章