Connection Settings
TheConnection class configures how MadelineProto connects to Telegram’s servers.
Overview
Properties
MTProto transport protocol to use
Transport layer (TCP, WebSocket, etc.)
Proxy configuration
Whether to use obfuscation (helps bypass ISP blocks)
Whether to connect to test servers
Whether to prefer IPv6
Connection timeout in seconds
Ping interval in seconds
Whether to retry failed connections
Whether to use DNS over HTTPS
Bind to specific address and port
Maximum number of media sockets
Round-robin period in seconds
Protocol Configuration
setProtocol
Set the MTProto transport protocol.Protocol class name
Returns self for method chaining
AbridgedStream (Recommended)
Lightest protocol with minimal overhead.- Overhead: Very small
- Envelope: 1-4 bytes
IntermediateStream
Standard protocol with small overhead.- Overhead: Small
- Envelope: 4 bytes
IntermediatePaddedStream
Padded version for use with obfuscation.- Overhead: Small-medium
- Envelope: Random length
- Best for: Bypassing ISP blocks
FullStream
Basic MTProto protocol with CRC and sequence checks.- Overhead: Medium
- Envelope: 12 bytes
- Features: CRC32 integrity check, sequence numbers
HttpStream / HttpsStream
For browsers and restricted webhosts.- Overhead: High
- Use case: Web environments, additional TLS security
getProtocol
Get the current protocol.Protocol class name
Transport Configuration
setTransport
Set the transport layer.Transport class name
Returns self for method chaining
DefaultStream- Standard TCP transportWsStream- Plain WebSocket transportWssStream- TLS WebSocket transport
getTransport
Get the current transport.Transport class name
Connection Parameters
setTimeout
Set connection timeout.Timeout in seconds
Returns self for method chaining
getTimeout
Get connection timeout.Timeout in seconds
setPingInterval
Set ping interval to keep connection alive.Interval in seconds
Returns self for method chaining
getPingInterval
Get ping interval.Interval in seconds
setRetry
Set whether to retry failed connections.Enable/disable retry
Returns self for method chaining
getRetry
Get retry setting.Whether retry is enabled
Network Options
setIpv6
Enable IPv6 connections.Enable/disable IPv6
Returns self for method chaining
getIpv6
Get IPv6 setting.Whether IPv6 is enabled
setUseDoH
Enable DNS over HTTPS.Enable/disable DoH
Returns self for method chaining
getUseDoH
Get DoH setting.Whether DoH is enabled
setBindTo
Bind connection to specific address.Address and port (e.g., “192.168.1.100:0”)
Returns self for method chaining
getBindTo
Get bind address.Bind address or null
Proxy Configuration
addProxy
Add a proxy to the connection.Proxy class name
Proxy configuration (address, port, username, password)
Returns self for method chaining
SOCKS5 Proxy
HTTP Proxy
setProxies
Set all proxies at once.Array of proxy configurations
Returns self for method chaining
clearProxies
Remove all proxies.Returns self for method chaining
getProxies
Get all configured proxies.Array of proxy configurations
Obfuscation
setObfuscated
Enable connection obfuscation to bypass ISP blocks.Enable/disable obfuscation
Returns self for method chaining
getObfuscated
Get obfuscation setting.Whether obfuscation is enabled
Test Mode
setTestMode
Connect to Telegram test servers.Enable/disable test mode
Returns self for method chaining
getTestMode
Get test mode setting.Whether test mode is enabled
Advanced Settings
setMaxMediaSocketCount
Set maximum number of media download sockets.Maximum socket count
Returns self for method chaining
setRobinPeriod
Set round-robin period for connections.Period in seconds
Returns self for method chaining
Complete Example
See Also
- AppInfo Settings - Configure API credentials
- Logger Settings - Configure logging
- Files Settings - Configure file operations