Flutter SDK

flutter sdk


# Flutter API

<p>[TOC]</p> <h1>tk_initSdk</h1> <ul> <li>Function: IOTC initialization, confirming the legality of sdkLicensekey</li> <li>The Key value needs to be applied to TUTK</li> </ul> <pre><code class="language-dart">/** IOTC Initial /// Initialize SDK, Change TUTK Server's realm /// Need to be called before IOTC_Initialize2() /// return TUTK_ER_NoERROR if successfully set master realm. /// * \return Error code if return value &amp;lt; 0 /// * - #TUTK_ER_INVALID_ARG if the region is invalid /// * - #TUTK_ER_INVALID_LICENSE_KEY if the key is invalid /// * - #TUTK_ER_MEM_INSUFFICIENT if the memory allocation failed /// * [licenseKey] The TUTK Server's realm to be used. */ static Future&amp;lt;int&amp;gt; tk_initSdk(String licenseKey); Example: FlutterTunnel.tk_initSdk('licensekey'); </code></pre> <h1>tk_connectTunnel</h1> <ul> <li>Function: Establish a Tunnel connection</li> </ul> <pre><code class="language-dart">/** Tunnel Connect /// This function is for a tunnel agent to connect a device /// * [connectInfo] /// var connectInfo = {&amp;quot;uid&amp;quot;: _uid, &amp;quot;username&amp;quot;: _username, &amp;quot;password&amp;quot;: _password}; /// * [_uid] The UID of that tunnel server to be connected /// * [_username] The predefined view account /// * [_password] The predefined view password /// return Tunnel session ID if return value &amp;gt;= 0 and equal to the input parameter SID. /// return Error code if return value &amp;lt; 0 */ static Future&amp;lt;int&amp;gt;tk_connectTunnel(Map connectInfo) Example: var connectInfo = {&amp;quot;uid&amp;quot;: _uid, &amp;quot;username&amp;quot;: &amp;quot;admin&amp;quot;, &amp;quot;password&amp;quot;: &amp;quot;testpwd&amp;quot;}; int sid = await FlutterTunnel.tk_connectTunnel(connectInfo);</code></pre> <h1>tk_startPortMapping</h1> <ul> <li>Function: Start mapping the ports on both ends</li> </ul> <pre><code class="language-dart">/** Port Mapping /// Start port mapping service /// This function used by a tunnel agent to start port mapping service // * provided by P2PTunnel module. The tunnel agent specifies the local port // * in local host through which a tunnel is created with the remote port defined // * in the tunnel server. /// * [portInfo] /// var portInfo = {&amp;quot;uid&amp;quot;: _uid, &amp;quot;localPort&amp;quot;: _localPort, &amp;quot;remotePort&amp;quot;: _remotePort}; /// * [_uid] The UID of that tunnel server to be connected /// * [_localPort] The local port used to create a tunnel with the tunnel server /// * [_remotePort] The remote port defined in the tunnel server to create a tunnel /// return The port mapping index if return value &amp;gt;= 0 /// return Error code if return value &amp;lt; 0 */ static Future&amp;lt;int&amp;gt;tk_startPortMapping(Map portInfo) Example: int webIndex; var portInfo = {&amp;quot;uid&amp;quot;: _uid, &amp;quot;localPort&amp;quot;: 10000, &amp;quot;remotePort&amp;quot;: 80}; try { webIndex = await FlutterTunnel.tk_startPortMapping(portInfo); } on Exception { webIndex = -1; }</code></pre> <h1>tk_stopPortMapping</h1> <ul> <li>Function: Stop mapping the ports on both ends</li> </ul> <pre><code class="language-dart">/** Stop Port Mapping /// Stop port mapping service /// This function used by a tunnel agent to stop port mapping service // * on a given port mapping index which is started by P2PTunnelAgent_PortMapping() /// * [portInfo] /// var portInfo = {&amp;quot;uid&amp;quot;: _uid}; /// * [_uid] The UID of that tunnel server to be connected */ static Future&amp;lt;void&amp;gt;tk_stopPortMapping(Map portInfo) Example: var portInfo = {&amp;quot;uid&amp;quot;: _uid}; FlutterTunnel.tk_stopPortMapping(portInfo); </code></pre> <h1>tk_disconnectTunnel</h1> <ul> <li>Function: Close Tunnel Connection</li> </ul> <pre><code class="language-dart">/** Disconnect /// It's to stop the progressing of connection. /// This API is for a client to stop connecting to a device. // * We can use it to stop connecting when client blocks in P2PTunnelAgent_Connect_Ex(). /// * [connectInfo] /// var connectInfo = {&amp;quot;uid&amp;quot;: _uid}; /// * [_uid] The UID of that tunnel server to be connected */ static Future&amp;lt;void&amp;gt;tk_disconnectTunnel(Map connectInfo) Example: var connectInfo = {&amp;quot;uid&amp;quot;: _uid}; FlutterTunnel.tk_disconnectTunnel(connectInfo);</code></pre> <h1>tk_unInitSdk</h1> <ul> <li>Function: IOTC uninitialization</li> </ul> <pre><code class="language-dart">/** IOTC Uninitial /// Deinitialize P2PTunnel module in a tunnel agent /// This function will deinitialize P2PTunnel module in a tunnel agent /// * \return #TUNNEL_ER_NoERROR if deinitialize successfully /// * \return Error code if return value &amp;lt; 0 */ static Future&amp;lt;void&amp;gt; tk_unInitSdk() Example: FlutterTunnel.tk_unInitSdk();</code></pre> <h1>tk_setTunnelStatusCB</h1> <ul> <li>Function: Report the status of the Tunnel connection</li> </ul> <pre><code class="language-dart">/** Tunnel connection status callback /// return the tunnel status /// This function will set a callback function pointer in P2PTunnel // * module for a tunnel agent to get the tunnel status from given callback // * function. Whenever tunnel status changes, P2PTunnel module will invoke // * the given callback function to notify tunnel agent with corresponding // * status. /// * [_uid] The UID of that tunnel server to be connected */ static Future&amp;lt;void&amp;gt; tk_setTunnelStatusCB(String _uid, void Function(dynamic) callback) Example: FlutterTunnel.tk_setTunnelStatusCB(_uid, (data) { String uid = data[&amp;quot;uid&amp;quot;]; int sid = data[&amp;quot;sid&amp;quot;]; int error = data[&amp;quot;error&amp;quot;]; setState(() { _tunnelStatusCB = error; if(_tunnelStatusCB &amp;lt; 0) { disconnectTunnel(); } }); }); </code></pre>

页面列表

ITEM_HTML