Link Establishment
Function Description
You can call the Connect API to establish a communication link for data transmission with the server. Both Prefill and Decode nodes can act as either the server or the client, depending on your configuration needs.
Scenario
Link establishment is a prerequisite for data transmission between nodes. The link establishment API adopts a TCP-like process, where the server provides listening information during initialization and the client initiates link establishment.
Example
Initialize HIXL. The listening host IP address and port number must be set on the server.
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"; // Replace it with the actual IP address and port number. It is the unique identifier of HIXL, and the port number must be a valid value. 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"; // Replace it with the actual IP address. It is the unique identifier of HIXL; the port can be omitted or set to a negative value, which indicates no listening. auto ret = engine.Initialize(local_engine, options); if (ret != SUCCESS) { printf("[ERROR] Initialize failed, ret = %u\n", ret); return -1; } |
Call Connect on the client to initiate a link establishment operation.
1 2 3 4 5 6 | AscendString remote_engine = "ip:port"; // Replace it with the local engine of the target server. auto ret = engine.Connect(remote_engine); if (ret != SUCCESS) { printf("[ERROR] Connect failed, ret = %u\n", ret); return -1; } |
Exception Handling
When the link establishment API call fails, check whether the network connection between the two devices is normal, whether the host IP address is correct, and whether the port is occupied.
For more troubleshooting methods, see HIXL Error Codes.