πWebSocket Integration Guide
This document explains how to build your own WebSocket client that connects to the AntVPN real-time protection system. The WebSocket interface is designed for persistent, low-latency communication.
This is ideal for game servers (Minecraft, etc.) that need to verify players in real time as they join.
If you want an already implemented websocket plugin for minecraft, you can use https://github.com/AntVPN/java-plugin/releases
Base URL
wss://api.antivpn.io/connectTable of Contents
Authentication
Connection Lifecycle
Message Protocol
Request Types
VERIFY
USER_DATA
PING
Response Types
SETTINGS
VERIFY
PONG
Keep-Alive & Heartbeat
Reconnection Strategy
Full Examples
Authentication
The WebSocket connection requires a JWT token passed in the Authorization header during the HTTP upgrade handshake.
The JWT token is issued by the AntVPN platform and contains the following claims:
uid
string
The unique identifier of the token/server.
owner
string
The account ID of the token owner.
If the token is missing, malformed, or expired, the server will reject the connection with an HTTP 401 Unauthorized or 400 Bad Request error before the WebSocket upgrade completes.
Connection Example (Handshake)
Connection Lifecycle
Once the WebSocket connection is established, the following sequence occurs:
Step-by-Step
Handshake β Client opens a WebSocket connection with the JWT in the
Authorizationheader.Settings delivery β Immediately after the connection is established, the server sends a
SETTINGSmessage containing the current protection configuration.Operational phase β The client sends
VERIFYrequests for each player that needs to be checked, andUSER_DATArequests to report player join/leave events.Heartbeat β The server sends WebSocket-level
PINGframes every 54 seconds. The client must reply with aPONGframe. If no pong is received within 60 seconds, the server closes the connection.
Message Protocol
All messages are sent as JSON text frames over the WebSocket connection. Every message (request or response) includes a type field that identifies what kind of message it is.
Request Structure
Response Structure
Request Types
1. VERIFY Request
Send a VERIFY request to check whether a player's IP address should be allowed or blocked. This is the primary message type you will use.
type
string
Yes
Must be "VERIFY".
transactionalId
string
Yes
A unique identifier for this request. Used to correlate the response back to the original request.
username
string
Yes
The player's in-game username.
userId
string
Yes
The player's unique identifier (e.g., Minecraft UUID).
address
string
Yes
The player's IP address (IPv4 or IPv6).
server
string
No
An optional identifier for the server/proxy the player is connecting to.
All required fields must be non-empty strings. If any required field is missing or empty, the request will be silently dropped.
How Detection Works
The server evaluates the IP against the following criteria:
Blacklist check β Is the IP present in the known abuser database?
ASN type check β Is the ASN type non-residential? (Only
isp,business,education,government, andunknownare considered safe.)Risk level check β Is the risk level above
elevated? (Onlyvery low,low, andelevatedare considered safe.)Username whitelist β If the username is explicitly whitelisted for the account, the IP check is bypassed entirely.
Custom filters β Account-specific filters can override the result to force-allow or force-block based on IP, ASN, or country.
Enabled state β If the protection is disabled in settings, all IPs are allowed regardless.
2. USER_DATA Request
Send a USER_DATA request to report player lifecycle events (joins, leaves, server switches). This data is used for analytics, session tracking, and shield-mode intelligence.
type
string
Yes
Must be "USER_DATA".
sessionId
string
Yes
The session ID received from a previous VERIFY response, linking this event to the original check.
username
string
Yes
The player's in-game username.
userId
string
Yes
The player's unique identifier.
address
string
Yes
The player's IP address.
hostname
string
Yes
The hostname the player connected through.
server
string
No
The server or sub-server identifier.
event
string
No
The event type. Common values: "PLAYER_JOIN", "PLAYER_SWITCH", "PLAYER_LEAVE".
version
string
No
The client version the player is using (e.g., "1.20.4").
premium
boolean
No
Whether the player has a premium/paid account.
Important: The event field determines how the server tracks online player counts:
PLAYER_JOINandPLAYER_SWITCHincrement the online player count.Any other event (including
PLAYER_LEAVE) decrements it.
3. PING Request
Send an application-level PING to verify the connection is alive. This is separate from the WebSocket protocol-level ping/pong frames.
type
string
Yes
Must be "PING".
nonce
string
Yes
A unique value that will be echoed back in the PONG response.
Response Types
1. SETTINGS Response
Sent by the server immediately after the connection is established. Contains the current protection configuration.
type
string
Always "SETTINGS".
settings.enabled
integer
1 if protection is active, 0 if disabled. When disabled, all IPs pass.
settings.kickMessage
string
The message displayed to blocked players.
settings.shieldMode
string
The shield mode message/configuration.
settings.updatedAt
string
Timestamp of the last settings update.
Your client should store these settings and apply them locally. For example, use kickMessage as the disconnect reason when blocking a player, and respect the enabled flag.
2. VERIFY Response
Returned in response to a VERIFY request. Tells you whether the player should be allowed or blocked.
type
string
Always "VERIFY".
transactionalId
string
Echoes the transactionalId from your request, so you can match responses to requests.
sessionId
string
A unique session ID generated by the server. Use this in subsequent USER_DATA messages for this player.
userId
string
The player's unique identifier (echoed back).
username
string
The player's username (echoed back).
serverId
string
The server identifier (echoed back).
address
string
The player's IP address (echoed back).
valid
boolean
true = allow the player. false = block the player.
is_attack
boolean
true if the system has detected a bot attack is in progress and has engaged shield mode for this connection.
How to Act on the Response
3. PONG Response
Returned in response to an application-level PING request.
type
string
Always "PONG".
nonce
string
The same nonce value you sent in the PING request.
Keep-Alive & Heartbeat
The WebSocket connection uses a dual-layer keep-alive mechanism:
WebSocket Protocol-Level Pings (Mandatory)
The server sends WebSocket
PINGframes every ~54 seconds.Your client must respond with a WebSocket
PONGframe automatically. Most WebSocket libraries handle this by default.If the server does not receive a
PONGwithin 60 seconds, it will close the connection.The write deadline for each message is 10 seconds. If a write takes longer, the connection is terminated.
Application-Level Pings (Optional)
Your client can send
PINGmessages (JSON) at any time to verify the connection is responsive.The server will reply with a
PONGmessage containing the samenonce.This is useful for measuring round-trip latency.
Timeout Summary
Write timeout
10 seconds
Maximum time to write a single message.
Pong timeout
60 seconds
Maximum time to wait for a pong after a ping.
Ping interval
54 seconds
How often the server sends ping frames.
Reconnection Strategy
Your client should implement automatic reconnection with the following best practices:
Detect disconnections β Listen for WebSocket close events and unexpected errors.
Exponential backoff β Wait before reconnecting, increasing the delay with each consecutive failure (e.g., 1s β 2s β 4s β 8s β max 30s).
Re-authenticate β Each new connection requires the full JWT handshake. There is no session resumption.
Re-apply settings β After reconnecting, wait for the new
SETTINGSmessage and update your local configuration.Re-verify active players β Any players who joined while disconnected should be re-verified.
Example Reconnection Logic (Pseudocode)
Full Examples
JavaScript (Browser / Node.js)
Java
Python
Shield Mode & Attack Detection
AntVPN includes an automatic Shield Mode that activates when a bot attack is detected:
The server tracks the rate of incoming
VERIFYrequests per connection.When the request rate exceeds the configured threshold, an attack state is activated.
During an attack, the system restricts joins to countries that historically make up the server's player base (countries representing more than 10% of total joins in the last month).
The
is_attackfield inVERIFYresponses indicates whether shield mode allowed the join during an active attack.When the attack ends, the system automatically deactivates shield mode.
You do not need to implement any shield logic on your side β just respect the valid field in VERIFY responses.
Error Handling Checklist
Invalid/expired JWT
Connection rejected with HTTP 400/401
Re-fetch a valid JWT and retry
Server sends WebSocket close frame
Connection terminates
Reconnect with exponential backoff
No pong received within 60s
Server closes the connection
Ensure your library handles pong frames
VERIFY response not received
Possible server issue or message lost
Implement a timeout (e.g., 10s) per check
valid field is true but attack
Player allowed, but shield mode is active
Allow the join, the server already filtered
Empty or malformed request
Server silently drops the message
Validate all fields before sending
Summary
Protocol
WebSocket (RFC 6455) over TLS
Endpoint
wss://api.antivpn.io/connect
Auth
JWT Bearer token in upgrade headers
Message format
JSON text frames
Request types
VERIFY, USER_DATA, PING
Response types
SETTINGS, VERIFY, PONG
Heartbeat
Server pings every 54s, 60s pong timeout
Reconnection
Client responsibility, use exponential backoff
Last updated