> For the complete documentation index, see [llms.txt](https://docs.monogoto.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monogoto.io/ntn-satellite-networks/udp-communication-for-ntn-applications/nordic-nrf9151-send-receive-udp-data.md).

# Nordic nRF9151: Send/Receive UDP Data

Start sending data to a UDP server, and from the server back to the device. For more information about getting started with the Nordic nRF9151, visit [this guide](/ntn-satellite-networks/ntn-certified-devices/ntn-certified-modules/nordic-nrf9151-satellite-ntn-network.md).

#### 1. Send Data from Your Device

**Create a UDP Socket**

```
AT#XSOCKET=1,2,0
```

Expected Response: <mark style="color:red;">`#XSOCKET: 0,2,17`</mark>

**Connect the Socket**

Replace <mark style="color:red;">`YOUR_SERVER_IP`</mark> and <mark style="color:red;">`PORT`</mark> (e.g. <mark style="color:red;">`9000`</mark>) with your server's ip address and port.

```
AT#XCONNECT="YOUR_SERVER_IP",PORT
```

Expected response: <mark style="color:red;">`#XCONNECT:1`</mark>

**Send UDP Payload**

Send the message <mark style="color:red;">`Hello World`</mark>&#x20;

```
AT#XSEND="Hello World"
```

Expected response: <mark style="color:red;">`%SOCKETDATA: 1,11`</mark>

**Close the UDP Socket**

```
AT#XSOCKET=0
```

Expected response: <mark style="color:red;">`#XSOCKET:0,"closed"`</mark>

On your server terminal, you should see:

```
Hello World
```

{% hint style="success" %}
Is the uplink working? Nice work! Let's continue with bidirectional communication.
{% endhint %}

***

#### 2. Enable Downlink (Server → Device)

Since the SIM by default doesn't have a public IP address, we can only send a downlink **immediately after receiving an uplink**, before the socket is closed. The server responds using the same IP address and port from which the data was received.

To test this, you'll need a UDP server that sends a response. You can use `socat` with a script that logs incoming data and sends "**ACK**" as a response:

```bash
socat UDP4-RECVFROM:9000,fork SYSTEM:'tee /dev/stderr > /dev/null; echo ack'
```

***

#### 3. Test Bidirectional Communication

On your device, send data and wait for a response.

**Start by opening the UDP port and send data to your UDP server:**

```
AT#XSOCKET=1,2,0
AT#XCONNECT="YOUR_SERVER_IP","PORT"
AT#XSEND="ICCID: 89999112345678901234; GPS: 50.078302,4.367782,8"
```

{% hint style="info" %}
On your server terminal, you should see:

```
ICCID: 89999112345678901234; GPS: 50.078302,4.367782,8
```

{% endhint %}

**Receive data over your UDP connection**

```
AT#XRECV=10
```

Expected response:

```
#XRECV: 4
ack

OK
```

Close the socket when done:

```
AT#XSOCKET=0
```

{% hint style="success" %}
Do you see the data appearing in the server, as well as the received downlink "**ACK**"? Great work! 🎉
{% endhint %}

***

### Troubleshooting

* **No data received on server**: Check your firewall allows UDP port 9000 (<mark style="color:red;">`ufw allow 9000/udp`</mark>)
* **Connection timeout on device**: Verify the server IP address is correct
* **No downlink received**: Make sure to call <mark style="color:red;">`AT#XRECV`</mark> before closing the socket
* **General connectivity issues**: Check device logs at [hub.monogoto.io](https://hub.monogoto.io) to verify device registration and connection status
