SOCKS5 UDP ASSOCIATE Error: Why It Happens and How to Fix It

Published:

11 minute read

Acar Diveroli
Written by: Acar Diveroli
Four stops on a rail: TCP socket, ASSOCIATE command, relay address, blue UDP relay; a TCP control line links them above

A SOCKS5 UDP ASSOCIATE error means the client cannot start UDP traffic through the proxy. The handshake has two parts. The client first asks for a relay over TCP, then sends packets to that relay over UDP. When one part drops silently, the client usually sees only a timeout. This post explains the steps of the handshake, the server reply codes, relay address problems and diagnosis with Python.

The UDP ASSOCIATE handshake

UDP ASSOCIATE is the SOCKS5 command that opens a relay on the server for UDP traffic. RFC 1928 defines three commands: CONNECT (0x01), BIND (0x02) and UDP ASSOCIATE (0x03). If the connectionless nature of UDP is new to you, read TCP vs. UDP first.

The flow has four steps:

  1. The client connects to the server over TCP and authenticates. The user:pass method is defined in RFC 1929.
  2. The client sends the 0x03 command. In the DST.ADDR and DST.PORT fields it writes the address it will send UDP from. If it does not know, it leaves both as zero.
  3. The server replies with BND.ADDR and BND.PORT. This is the relay address the datagrams go to.
  4. The client adds a header to each datagram and sends it to the relay. For an IPv4 target the header is 10 bytes and carries the real destination address and port.

Two rules decide where errors show up. The UDP association ends when the TCP connection that carried the request closes. The relay must also drop datagrams from any IP other than the one recorded for the association. A UDP packet carries no identity, so trust is tied to the source verified over TCP.

Apps that only send TCP

The most common cause is not in the protocol but in the app: many apps use SOCKS5 for TCP only. Most browsers and HTTP libraries read the proxy setting for CONNECT tunnels. They never send the UDP ASSOCIATE command. No error appears on the proxy side, because the request never arrives.

The result shows up in two ways. UDP traffic either bypasses the proxy and leaves from your own IP, or it does not leave at all. Local DNS queries, QUIC (HTTP/3) and voice calls are typical examples of this traffic. The first case is a leak, and it produces no error message.

The check is simple. Search the app's documentation for "SOCKS5 UDP" or "UDP ASSOCIATE" support. If the documentation says nothing, use a packet capture tool to see whether UDP packets go to the proxy or straight to the target. If they go straight to the target, the problem is in the client.

Server reply codes

If the server refuses the request, it says so in the REP field of the reply, and this is the easiest case to diagnose. RFC 1928 §6 defines nine values. These are the ones you will see most often with UDP ASSOCIATE:

CodeMeaningLikely cause
0x00SucceededThe problem is in a later step
0x01General server failureNo relay port could be allocated, or an internal error
0x02Not allowed by rulesetAn account or server rule blocks UDP
0x07Command not supportedThe server does not implement UDP ASSOCIATE
0x08Address type not supportedThe IPv6 address or domain in the request is not accepted

0x07 is the clearest message: the server does not support UDP at all. There is nothing to configure on the client; you need a server that supports UDP. 0x02 says the command is known but closed to you.

An authentication failure shows up elsewhere. Under RFC 1929, the server returns a non-0x00 status on failed authentication and closes the connection. The client never reaches the UDP ASSOCIATE step. If the connection closes before the command, check the username and password first.

BND.ADDR and the relay address

Datagrams can go to the wrong address even after a successful reply, because BND.ADDR is not always a usable address. Some servers return 0.0.0.0 in this field, and the RFC does not define what that value means. The common practice is to use the proxy address you connected to over TCP.

A client that uses the address as is gets an error. In our test on Windows, a sendto call to 0.0.0.0 returned [WinError 10049]. A similar trap appears with servers behind NAT: the server returns its own internal address (for example 10.x.x.x), which cannot be reached from outside.

There is a trap in the other direction too. If you write your local address and port into DST.ADDR, a NAT in between changes those values. If the server uses this information to restrict access, it treats your datagrams as coming from a foreign source and drops them. If you are not sure of your address, send zeros.

The control connection and NAT

The UDP association lives as long as the TCP control connection, and the relay stops when that connection closes. So a program that sends UDP must also keep its TCP socket open. A common mistake is closing the socket after the handshake, and leaving a with block in Python does that without you noticing. In our test, a datagram sent after the control connection closed got no reply.

An idle connection can also close, because firewalls along the path drop TCP connections that see no traffic for a long time. Turning on TCP keepalive (SO_KEEPALIVE) on the socket reduces this risk.

On the return path, NAT comes into play. The router opens a temporary mapping for the outgoing UDP packet and lets replies in through that mapping. RFC 4787 requires the mapping to live at least two minutes and recommends five minutes or more. A reply that arrives after a longer silence cannot get in. If the relay sends its reply from an address other than the BND address, a strictly filtering NAT drops that too. If packets go out but no reply comes back, the first suspect is the local firewall or NAT.

The handshake in Python

The script below performs the handshake with the standard library only. It authenticates with user:pass, requests UDP ASSOCIATE, corrects a 0.0.0.0 BND.ADDR, then sends one datagram and reads the reply. The target is a UDP echo server that you run. The script handles IPv4 replies only.

python
import socket
import struct
import sys

PROXY = ("pr.proxynet.io", 8000)
USER, PASS = b"user", b"pass"
TARGET = ("203.0.113.10", 9999)  # your own UDP echo server (example address)

REPLIES = {1: "general server failure", 2: "not allowed by ruleset",
           7: "command not supported", 8: "address type not supported"}

def recv_exact(s, n):
    buf = b""
    while len(buf) < n:
        chunk = s.recv(n - len(buf))
        if not chunk:
            raise ConnectionError("proxy closed the connection")
        buf += chunk
    return buf

# 1. TCP control connection and user:pass authentication (RFC 1929)
ctrl = socket.create_connection(PROXY, timeout=10)
ctrl.sendall(b"\x05\x01\x02")
assert recv_exact(ctrl, 2) == b"\x05\x02", "proxy did not select the user:pass method"
ctrl.sendall(b"\x01" + bytes([len(USER)]) + USER + bytes([len(PASS)]) + PASS)
assert recv_exact(ctrl, 2)[1] == 0, "authentication failed"

# 2. UDP ASSOCIATE (CMD=0x03); we don't know our address: 0.0.0.0:0
ctrl.sendall(b"\x05\x03\x00\x01" + socket.inet_aton("0.0.0.0") + b"\x00\x00")
ver, rep, _, atyp = recv_exact(ctrl, 4)
if rep != 0:
    sys.exit(f"UDP ASSOCIATE refused: 0x{rep:02x} {REPLIES.get(rep, '')}")
bnd_addr = socket.inet_ntoa(recv_exact(ctrl, 4))  # assumes IPv4 (ATYP=1)
bnd_port = struct.unpack("!H", recv_exact(ctrl, 2))[0]
if bnd_addr == "0.0.0.0":  # send to the proxy's TCP address
    bnd_addr = ctrl.getpeername()[0]
print("UDP relay:", bnd_addr, bnd_port)

# 3. Wrap the datagram in the UDP header and send it to the relay (RFC 1928 §7)
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp.settimeout(5)
header = b"\x00\x00\x00\x01" + socket.inet_aton(TARGET[0]) + struct.pack("!H", TARGET[1])
udp.sendto(header + b"hello", (bnd_addr, bnd_port))
data, _ = udp.recvfrom(65535)
print("reply:", data[10:])  # the first 10 bytes are the return header

# 4. The association lives while ctrl is open; closing it stops the relay
ctrl.close()

On a successful run the script prints two lines: the relay address and the reply. On a refusal it prints the REP code with its name. The third byte of the header is the FRAG field and must stay 0x00. Proxynet supports UDP over SOCKS5 connections; details are on the SOCKS5 Proxy page.

Debugging

The diagnosis follows the order of the handshake. Make sure the TCP side passes first, then look at UDP:

  1. Confirm that the app sends UDP through SOCKS.
  2. Log the authentication reply and the REP code.
  3. Print the BND.ADDR and BND.PORT values.
  4. Use a packet capture to see that the datagram reaches the relay and the reply comes back.
  5. Check that the TCP control connection stays open.
SymptomLikely causeWhat to do
UDP traffic leaves from your own IPThe app does not proxy UDPUse a client that supports UDP ASSOCIATE
Reply 0x07The server does not support UDPSwitch to a server that supports UDP
Reply 0x02A rule blocks UDPCheck the account and server rules
Connection closes before the commandAuthentication failedCheck the username and password
sendto error after a successful replyBND.ADDR is 0.0.0.0Use the proxy's TCP address
Packet goes out, no replyNAT or a firewall blocks the returnAllow inbound UDP, refresh the mapping
Works for a while, then stopsThe TCP control connection closedKeep the socket open, turn on keepalive

If you see the last row of the table, the problem is not in UDP but in TCP.

How we tested

We tested on December 1, 2026, on Windows 11 with Python 3.13.17. We wrote a local SOCKS5 test server with the standard library only. The server implemented RFC 1929 user:pass authentication and UDP ASSOCIATE. A local UDP echo server ran as the target. Each scenario ran in a fresh server process.

ScenarioResult
Normal handshake✓ reply echo:hello arrived
Server returns 0x07✗ the script reported the code by name
Server returns 0x02✗ the script reported the code by name
BND.ADDR 0.0.0.0✓ worked with the fix, [WinError 10049] without it
Datagram after TCP closed✗ no reply, [WinError 10054] locally
FRAG 0x01✗ the server dropped it, the client timed out

We did not connect to a real Proxynet endpoint. The results show protocol behavior, not a measurement of any specific server.

The bottom line

Look for a UDP ASSOCIATE error in the order of the handshake: app, REP code, relay address, return path, TCP connection. A Mobile Proxy also carries TCP and UDP over SOCKS5, and the same order applies to UDP jobs that need a mobile IP. Above all, confirm that the app really sends UDP to the proxy; if it does not, the traffic leaves silently from your own IP.

Sources

Frequently asked questions

Does SOCKS5 support UDP?

Yes. SOCKS5 relays UDP datagrams with the UDP ASSOCIATE command from RFC 1928. SOCKS4 does not include this command and carries TCP only. Protocol support is not enough, though: the server must implement the command, and the client app must send UDP through SOCKS. If either is missing, UDP either bypasses the proxy or does not go out at all.

What does the 0x07 command not supported error mean?

It means the server does not recognize or implement the UDP ASSOCIATE command. This reply does not come from a client setting. Changing the username, the port or the library will not change the result. For work that needs UDP, you have to switch to a SOCKS5 server that supports the command. The same server can keep opening TCP tunnels with CONNECT without trouble.

UDP ASSOCIATE succeeds but no reply arrives. Why?

Usually the return path is closed. The local firewall or NAT may not let the UDP packet from the relay in. Another possibility is that the client writes to the wrong address instead of BND.ADDR. If the TCP control connection has closed, the relay stops as well. Use a packet capture to check separately that the datagram goes out and that the reply comes in.

Why is BND.ADDR 0.0.0.0?

It means the server does not report a separate address for the relay. RFC 1928 does not define what this value means. The common fix is to use the proxy address you connected to over TCP as the IP and the BND.PORT from the reply as the port. In our test on Windows, sending directly to 0.0.0.0 returned [WinError 10049].

Does UDP keep working if I close the TCP connection?

No. Under RFC 1928, the UDP association ends when the TCP connection that carried the request closes. The relay port closes and later datagrams get no reply. In our test, the first datagram after the close also got no answer. Keep the control socket open as long as you send UDP, and use TCP keepalive for long idle periods.

Is authentication also done on UDP packets?

No. user:pass authentication happens only on the TCP control connection. UDP datagrams carry no credentials. The relay compares the source of each incoming packet with the client IP recorded when the association was set up and drops any that do not match. So on a network that sends TCP and UDP out through different external IPs, datagrams can be rejected.

Ask ChatGPTAsk Claude