开发者
资源

建链

功能介绍

调用Connect接口向Server侧建立通信链路,链路主要用于数据的传输,其中P/D均可作为Server或者Client,按需设置。

使用场景

建链操作是节点之间进行数据传输的前提,建链接口采用类TCP建链流程,Server初始化时提供侦听信息,由Client侧发起建链。

功能示例

  1. 初始化HIXL。其中Server侧需要设置侦听的Host IP和port。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    // Server侧
    Hixl engine;
    std::map<AscendString, AscendString> options;
    AscendString local_engine = "ip:port"; // 替换成真实IP端口;是HIXL的唯一标识,端口为有效值
    auto ret = engine.Initialize(local_engine, options);
    if (ret != SUCCESS) {
        printf("[ERROR] Initialize failed, ret = %u\n", ret);
        return -1;
    }
    // Client侧
    Hixl engine;
    std::map<AscendString, AscendString> options;
    AscendString local_engine = "ip:port"; // 替换成真实IP;是Hixl的唯一标识,端口可不设置或设置为负数,此时表示不侦听
    auto ret = engine.Initialize(local_engine, options);
    if (ret != SUCCESS) {
        printf("[ERROR] Initialize failed, ret = %u\n", ret);
        return -1;
    }
    
  1. 在Client侧调用Connect发起建链操作。
    1
    2
    3
    4
    5
    6
    AscendString remote_engine = "ip:port"; // 替换成需要与之建链的Server的local engine
    auto ret = engine.Connect(remote_engine);
    if (ret != SUCCESS) {
        printf("[ERROR] Connect failed, ret = %u\n", ret);
        return -1;
    }
    

异常处理

当调用建链失败时,需排查两台机器网络是否连通,Host IP是否正确,port是否被占用。

更多异常处理请参考HIXL错误码