【问题标题】:Using UNIX sockets with Dart在 Dart 中使用 UNIX 套接字
【发布时间】:2020-06-22 15:50:55
【问题描述】:

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

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

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

【问题讨论】:

    标签: dart unix-socket


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 2014-08-31
      • 1970-01-01
      • 2021-08-24
      • 1970-01-01
      • 2015-05-07
      相关资源
      最近更新 更多