.. _SLM_AT_TCP_UDP: TCP and UDP AT commands *********************** .. contents:: :local: :depth: 2 The following commands list contains TCP-related and UDP-related AT commands. When native TLS is used, you must store the credentials using the ``AT#XCMNG`` AT command. For more information on the networking services, visit the `BSD Networking Services Spec Reference`_. TCP server #XTCPSVR =================== The ``#XTCPSVR`` command allows you to start and stop the TCP/TLS server. Set command ----------- The set command allows you to start and stop the TCP/TLS server. Syntax ~~~~~~ :: #XTCPSVR=[[,]] * The ```` parameter can accept one of the following values: * ``0`` - Stop the server. * ``1`` - Start the server using IP protocol family version 4. * ``2`` - Start the server using IP protocol family version 6. * The ```` parameter is an unsigned 16-bit integer (0 - 65535). It represents the TCP service port. It is mandatory to set it when starting the server. * The ```` parameter is an integer. If it is given, a TLS server will be started. It indicates to the modem the credential of the security tag used for establishing a secure connection. Response syntax ~~~~~~~~~~~~~~~ :: #XTCPSVR: ,"started" #XTCPSVR: ,"not started" * The ```` value is an integer. When positive, it indicates the handle of the successfully opened listening socket. * The ```` value is an integer. It represents the error value according to the standard POSIX *errno*. Examples ~~~~~~~~ :: AT#XTCPSVR=1,3442,600 #XTCPSVR: 2,"started" OK Read command ------------ The read command allows you to check the TCP server settings. Syntax ~~~~~~ :: #XTCPSVR? Response syntax ~~~~~~~~~~~~~~~ :: #XTCPSVR: ,, * The ```` value is an integer. When positive, it indicates that the socket opened successfully. When negative, it indicates that the socket failed to open or that there is no incoming connection. * The ```` value is an integer. * ``1`` - IP protocol family version 4. * ``2`` - IP protocol family version 6. Examples ~~~~~~~~ :: AT#XTCPSVR? #XTCPSVR: 1,2,1 OK Test command ------------ The test command tests the existence of the command and provides information about the type of its subparameters. Syntax ~~~~~~ :: #XTCPSVR=? Response syntax ~~~~~~~~~~~~~~~ :: #XTCPSVR: (list of op value),, Examples ~~~~~~~~ :: AT#XTCPSVR=? #XTCPSVR: (0,1,2),, OK TCP/TLS client #XTCPCLI ======================= The ``#XTCPCLI`` command allows you to create a TCP/TLS client and to connect to a server. Set command ----------- The set command allows you to create a TCP/TLS client and to connect to a server. Syntax ~~~~~~ :: #XTCPCLI=[,,[,[sec_tag]] * The ```` parameter can accept one of the following values: * ``0`` - Disconnect. * ``1`` - Connect to the server for IP protocol family version 4. * ``2`` - Connect to the server for IP protocol family version 6. * The ```` parameter is a string. It indicates the hostname or the IP address to connect to. Its maximum size is 128 bytes. When the parameter is an IP address, it supports both IPv4 and IPv6. * The ```` parameter is an unsigned 16-bit integer (0 - 65535). It represents the TCP/TLS service port on the remote server. * The ```` parameter is an integer. If it is given, a TLS client will be started. It indicates to the modem the credential of the security tag used for establishing a secure connection. Response syntax ~~~~~~~~~~~~~~~ :: #XTCPCLI: , "connected" #XTCPCLI: , "not connected" * The ```` value is an integer. When positive, it indicates the handle of the successfully opened socket. * The ```` value is an integer. It represents the error value according to the standard POSIX *errno*. Examples ~~~~~~~~ :: AT#XTCPCLI=1,"remote.ip",1234 #XTCPCLI: 2,"connected" OK Read command ------------ The read command allows you to verify the status of the connection. Syntax ~~~~~~ :: #XTCPCLI? Response syntax ~~~~~~~~~~~~~~~ :: #XTCPCLI: , * The ```` value is an integer. When positive, it indicates the handle of the successfully opened socket. When negative, it indicates that the client socket failed to open. * The ```` value is an integer. * ``1`` - IP protocol family version 4. * ``2`` - IP protocol family version 6. Test command ------------ The test command tests the existence of the command and provides information about the type of its subparameters. Syntax ~~~~~~ :: #XTCPCLI=? Response syntax ~~~~~~~~~~~~~~~ :: #XTCPCLI: (op list),,, Examples ~~~~~~~~ :: AT#XTCPCLI=? #XTCPCLI: (0,1,2),,, OK TCP send data #XTCPSEND ======================= The ``#XTCPSEND`` command allows you to send the data over the connection. Set command ----------- The set command allows you to send the data over the connection. When used from a TCP/TLS client, it sends the data to the remote TCP server When used from a TCP server, it sends data to the remote TCP client Syntax ~~~~~~ :: #XTCPSEND= * The ```` parameter is a string that contains the data to be sent. The maximum size of the data is 1252 bytes. When the parameter is not specified, SLM enters ``slm_data_mode``. Response syntax ~~~~~~~~~~~~~~~ :: #XTCPSEND: * The ```` value is an integer. It represents the actual number of the bytes sent. Examples ~~~~~~~~ :: AT#XTCPSEND="Test TLS client" #XTCPSEND: 15 OK Read command ------------ The read command is not supported. Test command ------------ The test command is not supported. TCP hang up #XTCPHANGUP ======================= The ``#XTCPHANGUP`` command allows you to disconnect an incoming connection. Set command ----------- The set command allows you to disconnect an incoming connection. This function is reserved to TCP server role by its nature. Syntax ~~~~~~ :: #XTCPHANGUP= * The ```` parameter is an integer. Refer to ``#XTCPSVR?`` command for the ````. Response syntax ~~~~~~~~~~~~~~~ :: #XTCPSVR: ,"disconnected" * The ```` value is an integer of -111 or ECONNREFUSED. Examples ~~~~~~~~ :: AT#XTCPSVR? #XTCPSVR: 1,2,1 OK AT#XTCPHANGUP=2 #XTCPSVR: -111,"disconnected" OK Read command ------------ The read command is not supported. Test command ------------ The test command tests the existence of the command and provides information about the type of its subparameters. Syntax ~~~~~~ :: #TCPHANGUP=? Response syntax ~~~~~~~~~~~~~~~ :: #TCPHANGUP: Examples ~~~~~~~~ :: AT#TCPHANGUP=? #TCPHANGUP: OK TCP receive data ================ :: #XTCPDATA: * The ```` parameter is a string that contains the data received. * The ```` parameter is the size of the string, which is present only when SLM is not operating in ``slm_data_mode``. UDP server #XUDPSVR =================== The ``#XUDPSVR`` command allows you to start and stop the UDP server. NOTE DTLS server is not supported by nRF9160. Set command ----------- The set command allows you to start and stop the UDP server. Syntax ~~~~~~ :: #XUDPSVR=[,] * The ```` parameter can accept one of the following values: * ``0`` - Stop the server. * ``1`` - Start the server for IP protocol family version 4. * ``2`` - Start the server for IP protocol family version 6. * The ```` parameter is an unsigned 16-bit integer (0 - 65535). It represents the UDP service port. It is mandatory for starting the server. Response syntax ~~~~~~~~~~~~~~~ :: #XUDPSVR: ,"started" * The ```` value is an integer. It indicates the handle of the successfully opened listening socket. Examples ~~~~~~~~ :: AT#XUDPSVR=1,3442 #XUDPSVR: 2,"started" OK Read command ------------ The read command allows you to check the current value of the subparameters. Syntax ~~~~~~ :: #XUDPSVR? Response syntax ~~~~~~~~~~~~~~~ :: #XUDPSVR: , * The ```` value is an integer. When positive, it indicates the handle of the successfully opened socket. When negative, it indicates that it failed to open. * The ```` value is an integer. * ``1`` - IP protocol family version 4. * ``2`` - IP protocol family version 6. Test command ------------ The test command tests the existence of the command and provides information about the type of its subparameters. Syntax ~~~~~~ :: #XUDPSVR=? Response syntax ~~~~~~~~~~~~~~~ :: #XUDPSVR: (list of op value), Examples ~~~~~~~~ :: AT#XUDPSVR=? #XUDPSVR: (0,1,2), OK UDP/DTLS client #XUDPCLI ======================== The ``#XUDPCLI`` command allows you to create a UDP/DTLS client and to connect to a server. NOTE the UDP/DTLS client always works in a connection-oriented way. Set command ----------- The set command allows you to create a UDP/DTLS client and connect to a server. Syntax ~~~~~~ :: #XUDPCLI=[,,[,] * The ```` parameter can accept one of the following values: * ``0`` - Disconnect. * ``1`` - Connect to the server for IP protocol family version 4. * ``2`` - Connect to the server for IP protocol family version 6. * The ```` parameter is a string. It indicates the hostname or the IP address to connect to. Its maximum size can be 128 bytes. When the parameter is an IP address, it supports both IPv4 and IPv6. * The ```` parameter is an unsigned 16-bit integer (0 - 65535). It represents the UDP/DTLS service port on the remote server. * The ```` parameter is an integer. If it is given, a DTLS client will be started. It indicates to the modem the credential of the security tag used for establishing a secure connection. Response syntax ~~~~~~~~~~~~~~~ :: #XUDPCLI: ,"connected" #XUDPCLI: ,"not connected" * The ```` value is an integer. When positive, it indicates the handle of the successfully opened socket. * The ```` value is an integer. It represents the error value according to the standard POSIX *errno*. Examples ~~~~~~~~ :: AT#XUDPCLI=1,"remote.host",2442 #XUDPCLI: 2,"connected" OK Read command ------------ The read command allows you to check the current value of the subparameters. Syntax ~~~~~~ :: #XUDPCLI? Response syntax ~~~~~~~~~~~~~~~ :: #XUDPCLI: , * The ```` value is an integer. When positive, it indicates the handle of the successfully opened socket. When negative, it indicates that it failed to open. * The ```` value is an integer. * ``1`` - IP protocol family version 4. * ``2`` - IP protocol family version 6. Test command ------------ The test command tests the existence of the command and provides information about the type of its subparameters. Syntax ~~~~~~ :: #XUDPCLI: (op list),,, Examples ~~~~~~~~ :: AT#XUDPCLI=? #XUDPCLI: (0,1,2),,, OK UDP send data #XUDPSEND ======================= The ``#XUDPSEND`` command allows you to send data over the connection. Set command ----------- The set command allows you to send data over the connection. Syntax ~~~~~~ :: #XUDPSEND= * The ```` parameter is a string that contains the data to be sent. The maximum size of the data is 1252 bytes. When the parameter is not specified, SLM enters ``slm_data_mode``. Response syntax ~~~~~~~~~~~~~~~ :: #XUDPSEND: * The ```` value is an integer. It indicates the actual number of bytes sent. Examples ~~~~~~~~ :: AT#XUDPSEND="Test UDP by hostname" #XUDPSEND: 20 OK Read command ------------ The read command is not supported. Test command ------------ The test command is not supported. UDP receive data ================ :: #XUDPDATA: * The ```` parameter is a string that contains the data received. * The ```` parameter is the size of the string, which is present only when SLM is not operating in ``slm_data_mode``.