The OpenThread TCP APIs may be invoked via the OpenThread CLI.
Form a network with at least two devices.
On node 1, initialize the TCP CLI module and listen for incoming connections using the example TCP listener.
> tcp init > tcp listen :: 30000
The ::
specifies the IPv6 Unspecified Address.
On node 2, initialize the TCP CLI module, connect to node 1, and send a simple message.
> tcp init > tcp connect fe80:0:0:0:a8df:580a:860:ffa4 30000 > tcp send hello
After running the tcp connect
command on node 1, you should see a printout on node 1 similar to below:
TCP: Connection established
In addition, you should also see a printout on node 2 similar to below:
Accepted connection from [fe80:0:0:0:8f3:f602:bf9b:52f2]:49152 TCP: Connection established
After running the tcp send
command on node 1, you should see a printout on node 2 similar to below:
TCP: Received 5 bytes: hello
For a more in-depth example, see this video.
Unceremoniously ends the TCP connection, if one exists, associated with the example TCP endpoint, transitioning the TCP endpoint to the closed state.
> tcp abort TCP: Connection reset Done
Transfers the specified number of bytes using the TCP connection currently associated with the example TCP endpoint (this TCP connection must be established before using this command).
> tcp benchmark Done TCP Benchmark Complete: Transferred 73728 bytes in 7233 milliseconds TCP Goodput: 81.546 kb/s
Associates a name (i.e. IPv6 address and port) to the example TCP endpoint.
::
).> tcp bind :: 30000 Done
Establishes a connection with the specified peer.
If the connection establishment is successful, the resulting TCP connection is associated with the example TCP endpoint.
> tcp connect fe80:0:0:0:a8df:580a:860:ffa4 30000 Done TCP: Connection established
Deinitializes the example TCP listener and the example TCP endpoint.
> tcp deinit Done
List the TCP CLI commands.
> tcp help abort benchmark bind connect deinit help init listen send-message sendend stoplistening Done
Initializes the example TCP listener and the example TCP endpoint.
> tcp init Done
Uses the example TCP listener to listen for incoming connections on the specified name (i.e. IPv6 address and port).
If no TCP connection is associated with the example TCP endpoint, then any incoming connections matching the specified name are accepted and associated with the example TCP endpoint.
::
).> tcp listen :: 30000 Done
Send data over the TCP connection associated with the example TCP endpoint.
> tcp send hello Done
Sends the “end of stream” signal (i.e., FIN segment) over the TCP connection associated with the example TCP endpoint. This promises the peer that no more data will be sent to it over this TCP connection.
> tcp sendend Done
Stops listening for incoming TCP connections using the example TCP listener.
> tcp stoplistening Done