Usage

For usage in code, there is the class rcon.Client.

from rcon import Client

with Client('127.0.0.1', 5000, passwd='mysecretpassword') as client:
    response = client.run('some_command', 'with', 'some', 'arguments')

print(response)

Async support

If you want to use RCOn in an asynchronous environment, use rcon.rcon().

from rcon import rcon

response = await rcon('some_command', 'with', 'some', 'arguments',
                      host='127.0.0.1', port=5000, passwd='mysecretpassword')
print(response)

Configuration

rconclt servers can be configured in /etc/rcon.conf. The configuration file format is:

[<server_name>]
host = <hostname_or_ip_address>
port = <port>
passwd = <password>

The passwd entry is optional.

rconclt

rconclt is an RCON client script to communicate with game servers via the RCON protocol using the shell. To communicate with a server, run:

rconclt [options] <server> <command> [<args>...]

rconshell

rconshell is an interactive RCON console to interact with game servers via the RCON protocol. To start a shell, run:

rconshell [server] [options]

Handling connection timeouts.

You can specify an optional timeout=<sec> parameter to allow a connection attempt to time out. If a timeout is reached during a connection attempt, it will raise a socket.timeout exception. The following example will raise a connection timeout after 1.5 seconds:

try:
    with Client('127.0.0.1', 5000, timeout=1.5) as client:
        <do_stuff>
except socket.timeout as timeout:
    <handle_connection_timeout>