Appendix B – Detailed Examples
Multi-Tech Systems, Inc. AT Commands for Wireless Modems with IP Connectivity (S000333D)
78
Opening a TCP Socket
This example covers the following: Opening and using a TCP socket to a remote TCP server.
Description:
The modem provides a TCP socket API that allows the user to open a TCP session with a remote host.
The user can freely configure the IP address and TCP port of the remote server.
Only one TCP socket can be opened simultaneously.
Once the TCP session is opened, the modem acts as a transparent bridge between the TCP connection
and the serial port.
For a GPRS Internet connection, make sure that the operators are allowed to use the TCP port used by
your application.
Configuration:
TCP server
address
Defines the IP address of the remote TCP server. It must be configured as a 32-bit number in
dotted-decimal notation or as a symbolic name.
AT#TCPSERV
TCP server port
Defines the TCP port number of the remote TCP server. It can be configured with a 5-digit
number. For example the TCP port assigned to Telnet is usually 23. It must be the same between
the peers.
AT#TCPPORT
Closing mechanism
and DLE ETX
coding
Once the TCP connection is opened, either side can close it (the module’s ability to do this
depends on the DLEMODE parameter setting).
When the attached equipment wants to close the session, it must send an [ETX] character over
the serial port. In this case a coding mechanism (DLE based) must be applied to allow the
attached equipment to send [ETX] characters in the payload data.
The DLEMODE parameter defines if [ETX] characters received on the serial port must be
interpreted by the modem as a close command.
When the DLEMODE parameter is set to 0, an open TCP session can only be closed by the
remote TCP server.
AT#DLEMODE
[ETX] CTRL+C sequence in a keyboard
[DLE] CTRL+P sequence in a keyboard
Operation:
Opening the TCP
session
Once an IP link is established, this command instructs the modem to open a connection to the
remote TCP server as specified in the TCPSERV/TCPPORT parameters.
An ‘Ok_Info_WaitingForData’ message means that the operation has succeeded.
AT#OTCP
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 from the host to the remote is not echoed.
This link is bi-directional and the flow is controlled through the hardware 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].
Closing the TCP
session
If DLEMODE is set to 1, the attached host sends an [ETX] character to direct the modem to close
the current TCP session. This character is echoed
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.
If DLEMODE is set to 0, it is not possible for the attached host to close the TCP session.
[ETX] CTRL+C sequence in a keyboard
[DLE] CTRL+P sequence in a keyboard
Other AT# Parameters:
DLEMODE, TCPPORT, TCPSERV
Other AT# Commands:
LTCPSTART, LTCPSTOP, OTCP