Appendix B – Detailed Examples
Multi-Tech Systems, Inc. AT Commands for Wireless Modems with IP Connectivity (S000333D)
77
Setting a TCP Port to a Listening Mode
This example covers the following: Opening locally and listen to a TCP socket to accept incoming connections from
remote TCP clients.
Description:
The modem provides a TCP socket API that allows the user to open and listen to a TCP connection on
a configurable TCP port. The IP address of the remote client can be filtered if necessary.
Only one TCP session can be opened simultaneously.
Once the TCP session is opened, the modem acts as a transparent bridge between the TCP connection
and the serial connection.
For a GPRS Internet connection, make sure that the operators are allowed to use the TCP port used by
your application.
Configuration:
TCP client address Defines the IP address of the remote TCP client allowed to open the socket TCP. It must be
configured as a 32-bit number in dotted-decimal notation - not a symbolic name.
When this parameter is set to 255.255.255.255, the access is granted for all remote IP addresses.
AT#TCPSERV
TCP server port
Defines the TCP port number of the listening TCP socket. It can be configured with a 5-digit number.
For example, the TCP port assigned to Telnet is 23. It must be the same between the peers.
AT#TCPPORT
Operation:
Launching the
Listening TCP
session
Once an IP link is established, this command instructs the modem to listen to the incoming
connections on the TCP port specified in the TCPPORT parameter and issued by the allowed IP
address defined in the TCPSERV parameter.
AT#LTCPSTART
Opening the TCP
session
Upon detection of an incoming TCP connection from an allowed IP address on the specified TCP
port, the modem automatically opens the TCP session and issues an ‘Ok_Info_WaitingForData’
message over the serial port.
Data flow
Once the TCP socket has been successfully opened, all the data received from this session is sent
over the serial port and all the data received on the serial port is sent to the remote host within TCP
packets. Data received from the host are not echoed.
This link is bi-directional and the flow is controlled through the selected flow control mechanism.
If DLEMODE is set to 1, the attached host must send the [ETX] character as [DLE] [ETX] and the
[DLE] as [DLE] [DLE]. On the other hand, an [ETX] character received in the TCP payload data will
be transmitted over the serial port as a [DLE] [ETX] and a [DLE] as a [DLE] [DLE].
AT#DLEMODE
Closing the TCP
session from the
remote
•
If the remote ends the TCP session- (and if DLEMODE is set to 1)- the modem will also close the
socket TCP session by sending an [ETX] character over the serial port to the host, then the
message ‘Ok_Info_SocketClosed’.
•
If DLEMODE is set to 1, the attached host sends an [ETX] character to direct the modem to close
the current TCP session.
In this case the ‘Ok_Info_SocketClosed’ message signals that the TCP socket has been closed. An
‘OK’ message then indicates that the TCP process is completely finished.
As soon as the socket TCP is closed, the TCP port is not anymore in a listening mode.
If DLEMODE is set to 0, it is not possible for the attached host to close the TCP session in data
mode.
[ETX] CTRL+C sequence in a keyboard
[DLE] CTRL+P sequence in a keyboard
Closing the TCP
session from the
local host
When the modem is in TCP listening mode (launched by the AT#LTCPSTART command), this can
be stopped by the AT#LTCPSTOP command.
An ‘OK’ message then informs that the TCP process is completely finished.
If DLEMODE is set to 0, it is not possible for the attached host to close the TCP session.
AT#LTCPSTOP
Other AT# Parameters:
TCPSERV, TCPPORT, DLEMODE
Other AT# Commands:
LTCPSTART, LTCPSTOP, OTCP