OpenThread offers TCP commands for use with a Thread network to test peer-to-peer
communication between TCP endpoints. The
cli tcp provides one sample TCP
endpoint and one sample TCP listener with which all
Command overviews and the example that follows provide information on initializing the example TCP endpoint and TCP listener, how to connect to a peer TCP endpoint, and how to send a message to the peer.
For a list of
tcp commands, type
For descriptions and syntax of all commands, refer to the CLI Command Reference.
The TCP commands begin alphabetically with
tcp init command to initialize the TCP module to begin TCP communication.
The TCP module can then perform many functions, such as listening for incoming
connections using the example TCP listener provided by the
To deinitialize the example TCP listener and the example TCP endpoint,
tcp deinit command.
To bind the example TCP endpoint once you have initialized the TCP module,
tcp bind command to assign an IPv6 address and a port to the TCP endpoint.
This binds the endpoint for communication. Assigning the IPv6 address and port
is also referred to as "naming the endpoint."
To use the example TCP listener once you have initialized the TCP module,
tcp listen command and specify the IPv6 address and listening port.
To stop the example TCP listener from listening for incoming TCP connections,
tcp stoplistening command.
tcp connect command connects the example TCP endpoint to a peer TCP endpoint address.
Once a connection is established between two nodes, issue a
tcp send command
to send a message to the peer.
Once a TCP connection is established between two nodes, optionally use the
benchmark commands to send large amounts of data between the nodes to test
network bandwidth and performance. The number of transmitted bytes in milliseconds
as well as the TCP Goodput will be provided in the
To immediately and unceremoniously end a TCP connection, run the
command on either node to transition the TCP endpoint to a closed state.
When one node is done sending data to the other node, the first node can
tcp sendend command to alert the second node to no longer expect
data. The second node can also send a
tcp sendend to the first node.
Once each node receives a
TCP: Disconnected message, the TCP connection
between the two nodes is torn down. It is recommended but not required to
issue this command when data transfer is complete.
Send a message between two nodes
On node 1, initialize the TCP CLI module, then listen for incoming connections using the example TCP listener.
tcp listen :: 30000
The use of
::denotes that the
listenshould use the unspecified IPv6 address, thereby having the TCP/IPv6 stack assign the IPv6 address. The port is 30000.
On Node 2, initialize the TCP CLI module, connect to node 1, and then send a simple message.
tcp connect fe80:0:0:0:a8df:580a:860:ffa4 30000
tcp send hello
Based on the example steps shown above, the following output would be expected:
- After Node 2 runs the
tcp connectcommand, Node 2 should receive the message
TCP: Connection established.
- Node 1 should then receive the messages (with example IPv6 address and port):
Accepted connection from [fe80:0:0:0:8f3:f602:bf9b:52f2]:49152
TCP: Connection established
- After Node 2 runs the
tcp sendcommand, Node 1 should receive the message
TCP: Received 5 bytes: hello