10 Socket

The socket AT commands are used for creating and interfacing TCP/UDP sockets.

10.1 AT Commands

AT Command
Description
Create Socket
Create Persistent Socket
Socket TLS
Socket Connect
Socket Persistent
Socket Persistent Remove
Socket Persistent List
Socket Receive Mode
Socket Write String
Socket Write Binary
Close socket
Read Socket String
Socket Read Binary
Socket Error
Socket Listen
Socket Read From
Socket Peer Address
Socket Status
Socket Options
Socket Host by Name

10.1.1 AT+USOCR - Create Socket

Syntax
AT Command
Description
AT+USOCR=<protocol>[,<preferred_protocol_type>]
Creates a socket and associates it with the specified protocol (TCP or UDP).
Response
Description
+USOCR:<socket_handle>
Successful creation of socket.
Defined values
Parameter
Type
Description
protocol
enumerator
IP protocol.

Valid values:
6: TCP
17: UDP
preferred_protocol_type
enumerator
Selects the IP address type to use.

Valid values:
0: IPv4 address.
1: IPv6 address.

Default value: 0
socket_handle
integer
Socket identifier be used for any operation on that socket.

10.1.2 AT+USOPCR - Create Persistent Socket

Syntax
AT Command
Description
AT+USOPCR=<protocol>[,<preferred_protocol_type>]
Creates a persistent socket and associates it with the specified protocol (TCP or UDP).
A persistent socket will automatically re-connect when connection is lost.
It can also be stored so that the connection initiated on boot.


Notes:
Can be stored using AT&W.
Response
Description
+USOPCR:<socket_handle>
Successful creation of persistent socket.
Defined values
Parameter
Type
Description
protocol
enumerator
IP protocol.

Valid values:
6: TCP
17: UDP
preferred_protocol_type
enumerator
Selects the IP address type to use.

Valid values:
0: IPv4 address.
1: IPv6 address.

Default value: 0
socket_handle
integer
Socket identifier be used for any operation on that socket.

10.1.3 AT+USOTLS - Socket TLS

Syntax
AT Command
Description
AT+USOTLS=<socket_handle>,<tls_version>[,<ca_name>[,<client_cert_name>,<client_key_name>]]
Add a TLS context to a socket. This is only valid for TCP client sockets.
AT+USOTLS=<socket_handle>
Get the TLS context information for a socket.
Response
Description
+USOTLS:<socket_handle>,<tls_version>,<ca_name>,<client_cert_name>,<client_key_name>
Successful response with the TLS context information for the specified socket. The response includes the TLS version, CA name, client certificate name, and client key name.
Defined values
Parameter
Type
Description
tls_version
enumerator
Minimum TLS version to use

Valid values:
0: Disable TLS
1: TLS 1.2 or up
ca_name
string
Name of the certificate authority (CA) certificate to use

Valid length: 1..32
client_cert_name
string
Name of the client certificate to use

Valid length: 1..32
client_key_name
string
Name of the private key for client certificate

Valid length: 1..32
socket_handle
integer
Socket identifier be used for any operation on that socket.

10.1.4 AT+USOC - Socket Connect

For a TCP socket, this command will perform the TCP negotiation (3-way handshake) to open a connection and for a UDP socket this command will just declare the remote host address and port for later use with other socket operations.
Syntax
AT Command
Description
AT+USOC=<socket_handle>,<host_address>,<remote_port>
Establish a peer-to-peer connection to the specified remote host on the given remote port.
Defined values
Parameter
Type
Description
host_address
string
Remote host IP address or domain name of the remote host.

Valid length: 0..128
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_port
integer
The port of the remote peer.

Valid values: 1..65535
Notes
This command is non-blocking by default (can be configured with ${ref:AT+USOO}).
Notes for TCP sockets:
When socket is non-blocking (default), a connection is not fully set up until ${ref:+UESOC} URC is received.
Notes for UDP sockets:
Errors will not be reported prior to an attempt to write or read data on the socket. Since UDP is connectionless no ${ref:+UESOC} event will be sent, instead as soon as this command return OK the socket is ready for reading/writing data.

10.1.5 AT+USOP - Socket Persistent

Syntax
AT Command
Description
AT+USOP=<socket_handle>,<host_address>,<remote_port>
Configure a TCP link with automatic re-connection. As opposed to AT+USOC, this command will not initiate
a connection directly but is used for configuring a link that is automatically setup on boot.


Notes:
Requires AT&W and a reboot before taking effect.
Defined values
Parameter
Type
Description
host_address
string
Remote host IP address or domain name.

Valid length: 0..128
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_port
integer
The port of the remote peer.

Valid values: 1..65535
Example
Example of setting up a persistent TCP client connection that is loaded on boot: AT+USOPCR=6,0 AT+USOP=0,192.168.0.10,30123 AT&W AT+CPWROFF Please note that WiFi must also be setup.
Notes
Only one configuration is supported at the moment.

10.1.6 AT+USOPR - Socket Persistent Remove

Syntax
AT Command
Description
AT+USOPR=<config_id>
Removes an persistent socket configuration created by AT+USOPCR.


Notes:
Can be stored using AT&W.
Defined values
Parameter
Type
Description
config_id
integer
Configuration ID
Notes
The corresponding socket will be automatically closed.

10.1.7 AT+USOPL - Socket Persistent List

Syntax
AT Command
Description
AT+USOPL?
List all persistent socket configurations.
Response
Description
+USOPL:<socket_handle>,<host_address>,<remote_port>
The response for each persistent configuration.
Defined values
Parameter
Type
Description
config_id
integer
Configuration ID.
host_address
string
Remote host IP address or domain name of the remote host.

Valid length: 0..128
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_port
integer
The port of the remote peer.

Valid values: 1..65535

10.1.8 AT+USORM - Socket Receive Mode

Syntax
AT Command
Description
AT+USORM=<read_mode>
Set the mode in which you would like to receive data in AT mode.


Notes:
Any created sockets or created persistent sockets will use the same receive mode as was configured when they were created
Requires AT&W and a reboot before taking effect.
AT+USORM?
Read the current receive mode
Response
Description
+USORM:<read_mode>
Successful read response
Defined values
Parameter
Type
Description
read_mode
enumerator
Modes to read data in AT

Valid values:
0: Buffered mode
1: Direct String mode
2: Direct Binary Mode

10.1.9 AT+USOWS - Socket Write String

Syntax
AT Command
Description
AT+USOWS=<socket_handle>,<string_data>
Writes string data to the specified socket.
The command can be used for both TCP and UDP sockets after calling AT+USOC.
If socket is not ready to be written, generic negative error will be returned.
Check BSD errno (see BSD standard) by calling AT+USOE.
Response
Description
+USOWS:<socket_handle>,<written_length>
Successful write response.
Defined values
Parameter
Type
Description
written_length
integer
Data length that was written.
socket_handle
integer
Socket identifier be used for any operation on that socket.
string_data
string
Data encoded as ascii chars.

Valid length: 0..1000
Notes
This command is non-blocking.
The command may respond writing less data than what was passed to the command. This means that the socket transmit buffer is currently full and data not successfully written must be retransmitted later.

10.1.10 AT+USOWB - Socket Write Binary

Syntax
AT Command
Description
AT+USOWB=<socket_handle>{binary_data}
Writes binary data to the specified socket in binary mode.
Response
Description
+USOWB:<socket_handle>,<written_length>
Successful write response.
Defined values
Parameter
Type
Description
written_length
integer
Data length that was actually written to socket.
binary_data
binary
The data to write.
socket_handle
integer
Socket identifier be used for any operation on that socket.
Notes
This command is non-blocking.
The command may respond writing less data than what was passed to the command. This means that the socket transmit buffer is currently full and data not successfully written must be retransmitted later.

10.1.11 AT+USOCL - Close socket

Syntax
AT Command
Description
AT+USOCL=<socket_handle>
Closes the specified socket.

The command blocks the AT command interface until the completion of the socket close operation.
When this function returns OK the socket is cleaned up and fully closed.
Defined values
Parameter
Type
Description
socket_handle
integer
Socket identifier to be used for any future operation on that socket.

Valid values: 0..256

10.1.12 AT+USORS - Read Socket String

Syntax
AT Command
Description
AT+USORS=<socket_handle>,<length>
Reads the specified amount of data from the specified socket.
Note that the data should include no null terminator characters.
Response
Description
+USORS:<socket_handle>,<length>,<string_data>
Successful read response.
Defined values
Parameter
Type
Description
length
integer
Number of bytes to read.

Valid values: 1..1000
socket_handle
integer
Socket identifier be used for any operation on that socket.
string_data
string
Data encoded as ascii chars.

Valid length: 0..1000
Notes
This command is non-blocking.

10.1.13 AT+USORB - Socket Read Binary

Syntax
AT Command
Description
AT+USORB=<socket_handle>,<length>
Reads the specified amount of data from the specified socket in binary mode.
Response
Description
+USORB:<socket_handle>{binary_data}
Successful read response.
Defined values
Parameter
Type
Description
length
integer
Number of bytes to read.

Valid values: 1..1000
binary_data
binary
The available data. Please note that the number of bytes may be less than requested.
socket_handle
integer
Socket identifier be used for any operation on that socket.

10.1.14 AT+USOE - Socket Error

Syntax
AT Command
Description
AT+USOE
Retrieves the last error that occurred in any socket operation, stored in the socket errno.
Response
Description
+USOE:<error_code>
Successful response.
Defined values
Parameter
Type
Description
error_code
integer
BSD error code. See BSD standard for error code definitions.

10.1.15 AT+USOL - Socket Listen

Syntax
AT Command
Description
AT+USOL=<socket_handle>,<port>
Sets the specified socket in listening mode on the specified port of service, waiting for incoming connections (TCP) or data (UDP).
Defined values
Parameter
Type
Description
port
integer
Port of service, range 1-65535. Port numbers below 1024 are not recommended since they are usually reserved

Valid values: 1..65535
socket_handle
integer
Socket identifier be used for any operation on that socket.
Notes
For TCP sockets this command corresponds to BSD bind + listen and for UDP sockets BSD bind.

10.1.16 AT+USORF - Socket Read From

Syntax
AT Command
Description
AT+USORF=<socket_handle>,<length>
Reads the specified amount of data from the specified UDP socket.
Response
Description
+USORF:<socket_handle>,<remote_ip>,<remote_port>,<length>,<string_data>
Successful read response.
Defined values
Parameter
Type
Description
length
integer
Number of bytes to read.

Valid values: 1..900
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_ip
ip_addr
The ip address of the remote peer.
remote_port
integer
The port of the remote peer.

Valid values: 1..65535
string_data
string
Data encoded as ascii chars.

Valid length: 0..1000

10.1.17 AT+USOPA - Socket Peer Address

Syntax
AT Command
Description
AT+USOPA=<socket_handle>
Get the address of remote peer.
Response
Description
+USOPA:<socket_handle>,<remote_ip>,<remote_port>
Successful read response.
Defined values
Parameter
Type
Description
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_ip
ip_addr
The ip address of the remote peer.
remote_port
integer
The port of the remote peer.

Valid values: 1..65535

10.1.18 AT+USOST - Socket Status

Syntax
AT Command
Description
AT+USOST?
List status for all created sockets.
AT+USOST=<socket_handle>
Get the status of a specific socket.
Response
Description
+USOST:<socket_handle>,<protocol>,<socket_status>
Response for each created socket.
Defined values
Parameter
Type
Description
socket_status
enumerator
Valid values:
0: Not Connected
1: Listening
2: Connected
socket_handle
integer
Socket identifier be used for any operation on that socket.
protocol
enumerator
IP protocol.

Valid values:
6: TCP
17: UDP

10.1.19 AT+USOO - Socket Options

Syntax
AT Command
Description
AT+USOO=<socket_handle>,<option>,<value>
Set a socket option. See available options below.
AT+USOO=<socket_handle>,<option>
Read a socket option for a socket
Response
Description
+USOO:<socket_handle>,<option>,<value>
Successful read response
Defined values
Parameter
Type
Description
option
enumerator
Available options to set

Valid values:
0: Turn on/off No delay feature for TCP sockets.
Integer flag: 0 = off (i.e. Nagle algorithm enabled), 1 = on (i.e. Nagle algorithm disabled)
Default: to 0

1: Set socket to be blocking or non blocking.
Integer flag: 0 = off, 1 = on.
Sockets are non-blocking by default (Note that read/write will always be non-blocking).
Can only be set while the socket is in a non connected state.
Note: Only valid for non-persistent TCP sockets, will have no effect on UDP sockets

2: Keep connections alive by sending keepalive probes.
Integer flag: 0 = off, 1 = on.
To calculate the keepalive time us this formula KeepIdle + (KeepIntvl * KeepCnt).
Defaults to 1.
Note: Only valid for TCP sockets.

3: Set Keep Idle value for the socket.
This specifies the amount of time (in sec) that the connection must be idle before sending keepalive probes (if keepalive is enabled).
Defaults to 3.
Note: Only valid for TCP sockets.

4: Set keep alive interval value for the socket. This is the time in seconds between two successive keepalive retransmissions.
Defaults to 3.
Note: Only valid for TCP sockets.

5: Set keep alive counter value for the socket.
The number of unanswered probes required to force closure of the socket.
Defaults to 3.
Note: Only valid for TCP sockets.
value
integer
See option parameter
socket_handle
integer
Socket identifier be used for any operation on that socket.

10.1.20 AT+USOH - Socket Host by Name

Syntax
AT Command
Description
AT+USOH=<host_name>
Does a DNS lookup of a host name and returns the IP address.
Response
Description
+USOH:<host_ip>
Successful read response.
Defined values
Parameter
Type
Description
host_name
string
Name to lookup.

Valid length: 0..128
host_ip
ip_addr
The ip address of the host.

10.2 Unsolicited Response Codes

Unsolicited Response Code
Description
Event Socket Connection
Event Socket Data Available
Event Socket Data String
Event Socket Data String From
Event Socket Data Binary
Event Socket Data Binary From
Event Socket Closed
Event Socket Incoming Connection

10.2.1 +UESOC - Event Socket Connection

Event is sent out after a successful connection to a remote peer.
Syntax
+UESOC:<socket_handle>
Defined values
Parameter
Type
Description
socket_handle
integer
Socket identifier be used for any operation on that socket.
Notes
TCP only.

10.2.2 +UESODA - Event Socket Data Available

Data is available to be read. This will be sent out when using the buffered data mode.
Syntax
+UESODA:<socket_handle>,<number_bytes>
Defined values
Parameter
Type
Description
number_bytes
integer
Number of bytes available to read. If socket is a UDP socket this number refers to the size of the next datagram.
socket_handle
integer
Socket identifier be used for any operation on that socket.

10.2.3 +UESODS - Event Socket Data String

Incoming on TCP socket data represented as a string.
Syntax
+UESODS:<socket_handle>,<string_data>
Defined values
Parameter
Type
Description
socket_handle
integer
Socket identifier be used for any operation on that socket.
string_data
string
Data encoded as ascii chars.

Valid length: 0..1000

10.2.4 +UESODSF - Event Socket Data String From

Incoming on UDP socket data represented as a string.
Syntax
+UESODSF:<socket_handle>,<remote_ip>,<remote_port>,<string_data>
Defined values
Parameter
Type
Description
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_ip
ip_addr
The ip address of the remote peer.
remote_port
integer
The port of the remote peer.

Valid values: 1..65535
string_data
string
Data encoded as ascii chars.

Valid length: 0..1000

10.2.5 +UESODB - Event Socket Data Binary

Incoming on TCP socket data represented as binary data.
Syntax
+UESODB:<socket_handle>{binary_data}
Defined values
Parameter
Type
Description
binary_data
binary
The received data.
socket_handle
integer
Socket identifier be used for any operation on that socket.

10.2.6 +UESODBF - Event Socket Data Binary From

Incoming on UDP socket data represented as binary data.
Syntax
+UESODBF:<socket_handle>,<remote_ip>,<remote_port>{binary_data}
Defined values
Parameter
Type
Description
binary_data
binary
The received data.
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_ip
ip_addr
The ip address of the remote peer.
remote_port
integer
The port of the remote peer.

Valid values: 1..65535

10.2.7 +UESOCL - Event Socket Closed

Event is sent out either when a socket was closed (by the remote or timed out) or when a connection to a remote peer has failed. When this event is sent out the socket has been fully closed and the handle can be re-used.
Syntax
+UESOCL:<socket_handle>
Defined values
Parameter
Type
Description
socket_handle
integer
Socket identifier be used for any operation on that socket.
Notes
If there are unread data available, this event will not be sent out until all data has been read.

10.2.8 +UESOIC - Event Socket Incoming Connection

This event is sent when there is an incoming connection for a server socket.
Syntax
+UESOIC:<socket_handle>,<remote_ip>,<listening_socket_handle>
Defined values
Parameter
Type
Description
listening_socket_handle
integer
The handle of the new connected socket. Use this for any further operations on the connection.
socket_handle
integer
Socket identifier be used for any operation on that socket.
remote_ip
ip_addr
The ip address of the remote peer.
Last updated: 04 March 2025
Need help?Contact Support
Questions?Contact us