SOCKS5 UDP Associations with Node's socks Package
Use a SOCKS5 association and datagram framing when a Node application needs UDP through a proxy.
The Node socks package uses a SocksClient instance with command: 'associate' for UDP. Its convenient SocksClient.createConnection() factory handles TCP CONNECT instead.
The project's association example combines the SOCKS client with a separate local UDP socket:
- Establish UDP ASSOCIATE and retain its TCP control connection.
- Read the relay host and port returned by the server.
- Use
createUDPFrame()to frame outgoing payloads with their destination address. - Send the datagrams to the relay, then use
parseUDPFrame()on incoming relay frames before delivering payloads to the application.
Node's dgram socket supplies UDP transport; it does not interpret a SOCKS URL. The association and framing provide the proxy protocol around those datagrams.
The server must support UDP, and the relay endpoint must be reachable. A successful TCP connection to the initial proxy port does not test that path. Close the control and UDP resources when the association is no longer needed.