> ## Documentation Index
> Fetch the complete documentation index at: https://docs.joinmassive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SOCKS5 UDP

> Send UDP traffic, such as QUIC and HTTP/3, through Massive with SOCKS5 UDP ASSOCIATE

Massive supports the SOCKS5 `UDP ASSOCIATE` command ([RFC 1928, section 7](https://www.rfc-editor.org/rfc/rfc1928#section-7)) on the SOCKS5 port, with the same credentials as `CONNECT`.

| | |
| - | - |
| SOCKS5 Port | 65533 |
| Command | `UDP ASSOCIATE` (`0x03`) |

> [!NOTE]
>
> curl cannot send UDP through a SOCKS5 proxy. Use a client or library that supports SOCKS5 UDP ASSOCIATE.

## How it works

1. Open a TCP connection to `network.joinmassive.com:65533`, authenticate, and send `UDP ASSOCIATE`. `DST.ADDR` and `DST.PORT` in the request can be `0.0.0.0:0`.
2. The reply contains a relay address, `BND.ADDR:BND.PORT`. Send your datagrams, each with the standard SOCKS5 UDP header, to exactly that address and port. Replies come back from the same address and port.
3. Keep the TCP connection open while you use the association. Closing it ends the association.

> [!WARNING]
>
> Use the IP address from the reply as is. Do not resolve `network.joinmassive.com` again for the UDP traffic: it can point to a different server, which does not know your association.

## Sticky sessions and `udp-on`

UDP is available on a subset of our nodes. Add `udp-on` to the username of any session you plan to use for UDP, so the session is bound to a node that can carry it:

```text theme={null}
{PROXY_USERNAME}-session-37-udp-on:{API_KEY}
```

* Send `udp-on` on every request of that session, starting with the first one, TCP requests included. The session's TCP and UDP traffic then leave through the same exit node.
* `udp-on` also limits the session's TCP requests to UDP-capable nodes, so use it only for sessions that need UDP.
* Use `udp-on`. Invalid values are rejected.

Without `udp-on`, a session created by a TCP request may be bound to a node that cannot carry UDP. What happens then depends on the [session mode](https://docs.joinmassive.com/residential/sticky-sessions.md#session-modes):

| Session mode | What happens to `UDP ASSOCIATE` |
| - | - |
| `strict` | Moves the session to a UDP-capable node, so the session's TCP exit changes too |
| `flex` | Fails until the error limit (`sessionerr`) is reached. Successful TCP requests on the session reset that count |
| `norotate` | Fails until the sticky session TTL (`sessionttl`) expires |

Adding `udp-on` later moves a `strict` or `flex` session to a UDP-capable node on its next request. A `norotate` session never moves, so that request fails, TCP included: start a new session ID with `udp-on` instead.

## Limitations

* **Same source IP.** Send datagrams from the same public IP address as the TCP connection that sent `UDP ASSOCIATE`. Datagrams from any other IP are dropped. The source port can vary, and you can use several UDP sockets from that IP under one association. Watch for networks where UDP leaves from a different public IP than TCP, such as carrier-grade NAT pools, dual-stack hosts, or multi-WAN setups. The relay address uses the same IP version as your TCP connection.
* **First datagram.** Send the first datagram within 10 seconds of the reply, or the association is closed.
* **Lifetime.** An association ends when you close the TCP connection or after 5 minutes without traffic in either direction. An active association is also closed 24 hours after it opens; open a new one to continue.
* **One exit node.** An association stays on the node it started on, even after the sticky session TTL (`sessionttl`) expires. If that node goes offline, the association ends; send a new `UDP ASSOCIATE`.
* **Exit node, not exit IP.** TCP and UDP traffic in one session share an exit node. They usually share its IP address too, but a node with more than one network connection can send them from different addresses, so this is not guaranteed.
* **Ports and content.** UDP follows the same [usage restrictions](https://docs.joinmassive.com/residential/usage-restrictions.md) as TCP: only the destination ports open for your account (80, 443 and 53 by default), no private or local addresses, and blocked domains stay blocked. A datagram that breaks a rule is dropped without an error, because SOCKS5 cannot report errors for single datagrams.
* **No fragmentation.** Datagrams with a non-zero `FRAG` field are dropped.
* **Datagram size.** The SOCKS5 header adds 10 to 262 bytes to every datagram, and your network path to the proxy must carry the total. Keep payloads at or below about 1,280 bytes, the QUIC default. If a QUIC handshake hangs with no error on either side, check your path MTU first.

## HTTP/3 in browsers

Name resolution through the proxy does not return the DNS records that announce HTTP/3. A browser therefore loads a site over HTTP/2 first and switches to HTTP/3 from the next load, using the site's `Alt-Svc` header. Test with at least two page loads. A client that resolves names itself can send its DNS queries to UDP port 53 through the association and use HTTP/3 from the first load.

## Errors

If the proxy cannot set up the association, it answers `UDP ASSOCIATE` with an error reply and closes the connection. There is no fallback to TCP.

| Reply | Meaning | What to do |
| - | - | - |
| `0x01` | No UDP-capable node matches the request, or the node failed | Retry, add `udp-on`, or relax geo or device targeting |
| `0x09` | Invalid username parameters, such as a wrong `udp` value | Fix the username |
| `0x0B` | No route matches your targeting | Relax geo or device targeting |

## Usage accounting

UDP traffic counts toward your usage like TCP traffic: the payload of your datagrams in both directions. SOCKS5 headers are not counted. Usage for an association is recorded when it ends.

## Examples

### PySocks (UDP, Python)

A DNS lookup over SOCKS5 UDP ASSOCIATE with [PySocks](https://github.com/Anorov/PySocks) (1.7.1); the username must carry `-udp-on`.

```python theme={null}
import socket, struct, socks  # pip install PySocks

PROXY_HOST, PROXY_PORT = "network.joinmassive.com", 65533
USERNAME = "{PROXY_USERNAME}-udp-on"   # the -udp-on suffix is REQUIRED for UDP
PASSWORD = "{API_KEY}"

# Build a minimal DNS A-record query for example.com
query = struct.pack(">HHHHHH", 0x1234, 0x0100, 1, 0, 0, 0)
for label in (b"example", b"com"):
    query += bytes([len(label)]) + label
query += b"\x00" + struct.pack(">HH", 1, 1)       # end of name, QTYPE=A, QCLASS=IN

# SOCKS5 UDP ASSOCIATE: set_proxy on a UDP socket, then sendto/recvfrom.
sock = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM)
sock.set_proxy(socks.SOCKS5, PROXY_HOST, PROXY_PORT, username=USERNAME, password=PASSWORD)
sock.settimeout(10)
sock.sendto(query, ("1.1.1.1", 53))               # first datagram opens the UDP relay
data, _ = sock.recvfrom(4096)
sock.close()

# Print the A records from the answer section (the reply echoes the question)
offset = len(query)
for _ in range(struct.unpack(">H", data[6:8])[0]):
    offset += 2                                   # compressed name pointer (0xc0 0x0c)
    rtype, _, _, rdlen = struct.unpack(">HHIH", data[offset:offset + 10]); offset += 10
    if rtype == 1:
        print("example.com ->", socket.inet_ntoa(data[offset:offset + 4]))
    offset += rdlen
```

### CloakBrowser (HTTP/3)

Load a page over HTTP/3, with QUIC carried by the SOCKS5 UDP relay, using CloakBrowser.

```python theme={null}
from cloakbrowser import launch

# Massive residential SOCKS5 proxy. "-udp-on" pins UDP-capable exit nodes so QUIC
# can ride the SOCKS5 UDP ASSOCIATE relay.
proxy = "socks5://{PROXY_USERNAME}-udp-on:{API_KEY}@network.joinmassive.com:65533"

# --origin-to-force-quic-on makes Chromium use HTTP/3 on the first load.
browser = launch(
    proxy=proxy,
    headless=True,
    args=["--origin-to-force-quic-on={TARGET_HOST}:443"],
)
page = browser.new_context().new_page()
resp = page.goto("https://{TARGET_HOST}/")

# Confirm the page arrived over HTTP/3 (QUIC over SOCKS5 UDP).
proto = page.evaluate("performance.getEntriesByType('navigation')[0].nextHopProtocol")
print(resp.status, proto)   # -> 200 h3
browser.close()
```

`--origin-to-force-quic-on` forces HTTP/3 with no TCP fallback, so point it at a host you know serves HTTP/3. Without the flag, the first load is HTTP/2 and HTTP/3 appears on the next load through `Alt-Svc` (see [HTTP/3 in browsers](#http3-in-browsers)).

> [!NOTE]
>
> CloakBrowser resolves QUIC targets itself, so QUIC follows your DNS answer, not the exit node's.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.