Xirsys.Sockets.Client (xturn_sockets v1.2.0)
View SourceTCP protocol socket client for TURN server usage.
Handles TCP connections with buffering and provides 5-tuple information to callbacks for proper STUN/TURN protocol processing.
## Callback Interface
Your callback module must implement:
def process_buffer(data, client_ip, client_port, server_ip, server_port)
Where:
data
- Binary data from TCP stream (may be partial packets)client_ip
- Client IP address tupleclient_port
- Client port numberserver_ip
- Server IP address tupleserver_port
- Server port number
The function should return {parsed_packet, remaining_buffer}
where:
parsed_packet
- Complete packet ready for processing (ornil
if incomplete)remaining_buffer
- Any remaining unparsed data
The 5-tuple information is essential for STUN/TURN over TCP (RFC 5389, RFC 5766).
Example
defmodule MyTCPHandler do
def process_buffer(data, client_ip, client_port, server_ip, server_port) do
case parse_stun_packet(data, client_ip, client_port, server_ip, server_port) do
{:ok, packet, rest} -> {packet, rest}
{:partial, _} -> {nil, data} # Wait for more data
end
end
def dispatch(conn) do
# Process complete STUN/TURN packet
handle_packet(conn.message, conn)
end
end
Summary
Functions
Returns a specification to start this module under a supervisor.
Asynchronous socket response handler
Message handler to update cache
Callback implementation for GenServer.init/1
.
Standard OTP module startup
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Asynchronous socket response handler
Message handler to update cache
Callback implementation for GenServer.init/1
.
Standard OTP module startup