XBee® Wi-Fi RF Modules
© 2013 Digi International, Inc. 47
TCP packets may be sent on an existing connection or on a new connection. In order to
send data on an existing TCP connection, the destination IP address and port in the API
packet must match the remote IP address and port in an existing socket. In a sample
application, a packet may arrive that expects return data on the same socket. The API
frame (Rx IPv4) will contain the remote IP address and port. While the remote IP
address may be predicted, the remote IP address cannot. Therefore, the return data
should be sent to the remote IP address and port by swapping the source and
destination port numbers.
If the destination IP address and port don’t match an existing connection, the frame will
be discarded, unless the source port is 0. A source port of 0 allows the module to create
a new TCP client socket if the requested socket connection doesn’t already exist, and if a
socket resource is available.