Note: The original documentation in Russian is available in README_ru.md.
APTCP-SOCKS Tunnel is an asynchronous SOCKS5 proxy server and client operating over the session-based APTCP (aioptcp) transport protocol. It provides high fault tolerance and seamless connection continuity during short-term network disruptions, interface switching (Wi-Fi/LTE), or IP address changes.
The project supports full SOCKS5 (RFC 1928) functionality, including TCP CONNECT and UDP ASSOCIATE (for SOCKS5 clients such as Proxifier, Postern, etc.), as well as authentication under the RFC 1929 standard via .jsonl files.
-
Network Connection Resilience: During temporary network outages, the logical SOCKS5 channel does not drop but buffers transmitted data.
aioptcpautomatically restores the underlying physical TCP channel in the background without any packet loss. -
Full UDP Support: Complete implementation of the SOCKS5
UDP ASSOCIATEcommand. It proxies UDP datagrams in both directions over a single resilient tunnel. -
Two-tier Authentication:
- Application
$\rightarrow$ SOCKS5 Client (RFC 1929 Username/Password). - SOCKS5 Client
$\rightarrow$ APTCP Server (Tunnel Authentication).
- Application
-
JSONL User Configuration: Easily manage user accounts using simple
{"username": "...", "password": "..."}JSON lines. - TLS Encryption Support: Optional traffic encryption between client and server with server certificate verification.
The easiest way to set up the APTCP server is to use the included install.sh script located in the root directory. This script automates repository cloning, configuration setup (port, users), and optional TLS certificate generation.
If you have uploaded the install.sh file from a Windows machine, you must clean it from Windows line endings and grant execution permissions before running:
- Fix line endings:
sed -i 's/\r//' install.sh - Make it executable:
chmod +x install.sh
- Run the script:
./install.sh
Alternatively, you can run the installer directly via a one-liner:
curl -O https://raw.githubusercontent.com/Doctorgth/APTCP-SOCKS/main/install.sh && sed -i 's/\r//' install.sh && chmod +x install.sh && ./install.sh.
├── common/ # Common modules (config parsing, SOCKS5 parser, tunnel framing)
│ ├── config.py
│ ├── socks5.py
│ └── tunnel.py
├── client/ # Local SOCKS5 proxy client
│ ├── aptcp_client.py
│ ├── socks_server.py
│ ├── config.json.example # Client configuration template
│ ├── users.jsonl
│ └── main.py
├── server/ # Remote APTCP SOCKS5 server
│ ├── aptcp_server.py
│ ├── socks_handler.py
│ ├── config.json.example # Server configuration template
│ ├── users.jsonl.example # Server users template
│ └── main.py
├── tests/ # Autotests (SOCKS5, Tunnel, Auth, E2E, and resilience tests)
├── Dockerfile # Dockerfile for the server side
├── docker-compose.yml # Docker Compose configuration for the server
├── requirements.txt
└── README.md
The server side supports two deployment scenarios: automated deployment using Docker Compose and manual start.
This is the easiest way to deploy the server. It does not require installing Python or dependencies on the host machine.
- Copy the following files and directories to your remote Linux server:
common/server/Dockerfiledocker-compose.ymlrequirements.txt
- Create configuration files from the templates:
cp server/config.json.example server/config.json cp server/users.jsonl.example server/users.jsonl
- (Optional) Edit the authorization credentials in
server/users.jsonland network ports inserver/config.json. The default port is1080. - Start the service in the background:
docker compose up -d
- Check logs to ensure everything is running correctly:
docker compose logs -f
- Ensure Python 3.11+ is installed on your system.
- Install the required dependencies:
pip install -r requirements.txt
- Copy the configuration templates:
cp server/config.json.example server/config.json cp server/users.jsonl.example server/users.jsonl
- Set up authorization credentials in
server/users.jsonl. - Run the server:
python -m server.main server/config.json
The system uses a two-stage authentication mechanism. To avoid configuration confusion, please note the difference between local and tunnel authentication:
- What it does: Controls whether local applications (like Proxifier) are allowed to connect to the locally running SOCKS5 proxy on port
1080. - Configuration: Managed in
client/config.jsonvia the"auth_enabled"flag and the user list inclient/users.jsonl. - How it works:
- If
"auth_enabled": true, you must enable authentication in your Proxifier settings and enter one of the credentials defined inclient/users.jsonl(e.g.,proxifier/proxifier_password). - If
"auth_enabled": false, Proxifier will access the local SOCKS5 proxy without a password (select «None» / «No Authentication» in Proxifier). The tunnel to the remote server will still remain fully secure!
- If
- What it does: Grants the local client permission to establish a secure transport tunnel with the remote server.
- Configuration: Configured in
client/config.json(the"aptcp_username"and"aptcp_password"fields) and validated againstserver/users.jsonlon the server. - How it works:
- The local client always reads the username/password from its own
client/config.jsonand submits them to the remote server on connection. - You do not need to enter these credentials in Proxifier! Proxifier is completely unaware of the tunnel transport auth; the client handles it under the hood automatically.
- The local client always reads the username/password from its own
The client runs on your local machine and provides a standard local SOCKS5 port for applications.
- Copy the client configuration template:
cp client/config.json.example client/config.json
- Edit
client/config.json, specifying:aptcp_server_host: The IP address or domain name of your remote Linux server.aptcp_server_port: The port where your APTCP server is listening (default is1080).aptcp_username/aptcp_password: The credentials defined on the server side inusers.jsonl.
- Set up the local authentication database for your apps by copying and editing the user list template:
(Enter these credentials into your Proxifier/Postern settings if local auth is enabled).
cp client/users.jsonl.example client/users.jsonl
- Start the client application:
python -m client.main client/config.json
To protect transmitted traffic, it is recommended to enable TLS encryption between the SOCKS5 client and the APTCP server.
Generate a private key and a certificate on your Linux server:
openssl req -x509 -newkey rsa:2048 -keyout server/key.pem -out server/cert.pem -days 365 -nodes -subj "/CN=your_domain_or_ip"Ensure that both key.pem and cert.pem are saved inside the server/ directory.
Enable TLS support in server/config.json:
{
"aptcp_host": "0.0.0.0",
"aptcp_port": 1080,
"auth_enabled": true,
"users_file": "server/users.jsonl",
"timeout": 30,
"tls_enabled": true,
"tls_cert": "server/cert.pem",
"tls_key": "server/key.pem"
}If using Docker Compose, make sure to uncomment the certificate volumes in docker-compose.yml before starting.
- Copy the public server certificate (
cert.pem) from your server to your local machine, saving it asclient/server_cert.pem. - Activate TLS in
client/config.json:Note: If you are using a self-signed certificate and omit the{ ... "aptcp_tls_enabled": true, "aptcp_tls_ca_cert": "client/server_cert.pem" }aptcp_tls_ca_certparameter, the client will connect in an insecure mode (disabling certificate and host validation), which is convenient for quick debugging but not recommended for production use.
The test suite checks SOCKS5, UDP, authentication, and background session restoration resilience:
# Run all tests
pytest -v
# Run E2E tests (including physical link reconnection tests)
pytest tests/test_e2e.py -vCopyright 2026 APTCP-SOCKS Tunnel (https://github.com/Doctorgth)
Licensed under the Apache License, Version 2.0.