Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Expose API to connect/disconnect client #2

Open
AngellusMortis opened this issue Jan 1, 2025 · 0 comments
Open

Feature Request: Expose API to connect/disconnect client #2

AngellusMortis opened this issue Jan 1, 2025 · 0 comments

Comments

@AngellusMortis
Copy link

AngellusMortis commented Jan 1, 2025

So currently you have to use the GameRCON as a context manager to connect/disconnect to a server:

client = GameRCON('host', 'port', 'password', timeout=10)
async with client as pot_client:
    response = await pot_client.send('your_command')
    print(response)

If you want to manage this yourself (connection pooling), you have to call __aenter__ and __aexit__ directly which does not feel very clean. It would be nice of the contents of both are moved to a stable connect/disconnect API method so you can manage the connect yourself instead of faking the context manager:

client = GameRCON('host', 'port', 'password', timeout=10)
await client.connect()
try:
    response = await pot_client.send('your_command')
    print(response)
finally:
    await client.disconnect()

Example use case:

You have multiple servers running and you want to do a rolling restart of them and then notify users of the status as they restart. Very rough code that probably does not even work:

servers = [(ip, port, password), (ip, port, password), (ip, port, password)...]
clients = [GameRCON(ip, port, password) for ip, port, password in servers]

try:
    await asyncio.gather(*[await c.connect() for c in clients])
    await asyncio.gather(*[await c.send("Broadcast Test") for c in clients])
finally:
    await asyncio.gather(*[await c.disconnect() for c in clients])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant