Create a simple Clacks Server Instance

PHOTO EMBED

Sun Apr 02 2023 15:24:44 GMT+0000 (Coordinated Universal Time)

Saved by @MaVCArt #python

import clacks

# -- create a simple server instance.
# -- All keyword arguments can be left to their default in most cases.
server = clacks.ServerBase(identifier='My First Clacks Server')

# -- create a handler. Handlers are how the Server receives input requests.
handler = clacks.JSONHandler(clacks.JSONMarshaller(), server=server)

# -- once a handler has been created, it needs to be registered on a host/port combo.
server.register_handler_by_key(host='localhost', port=9998, handler_key='simple', marshaller_key='simple')

# -- give the server something to do - the "standard" interface contains some basic methods.
server.register_interface_by_key('standard')

# -- start the server. By setting "blocking" to True, we block this interpreter instance from progressing.
# -- Setting "blocking" to False instead would not stop this interpreter instance from continuing, so the server
# -- would die if the interpreter instance reaches its exit point.
server.start(blocking=True)
content_copyCOPY

This snippet creates a simple blocking clacks server with default commands and a JSON handler