Skip to content

Instantly share code, notes, and snippets.

@sennachereeb
Last active May 19, 2025 15:09
Show Gist options
  • Save sennachereeb/e5191528f5ed5e4d99ef4c877e7aaf46 to your computer and use it in GitHub Desktop.
Save sennachereeb/e5191528f5ed5e4d99ef4c877e7aaf46 to your computer and use it in GitHub Desktop.
import os
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react
from twisted.spread.pb import Broker, PBClientFactory, RemoteReference
class MyPBClientFactory(PBClientFactory):
def __init__(self):
super().__init__()
def clientConnectionMade(self, broker: Broker):
print("RAW client connected.")
super().clientConnectionMade(broker)
@react
@inlineCallbacks
def main(reactor):
local_endpoint: TCP4ClientEndpoint = TCP4ClientEndpoint(
reactor,
os.environ.get('SERVER_HOST'),
int(os.environ.get('SERVER_PORT')))
client_factory: MyPBClientFactory = MyPBClientFactory()
_: Broker = yield local_endpoint.connect(client_factory)
root: RemoteReference = yield client_factory.getRootObject()
data: str = yield root.callRemote("echo", "HELLO RAW!")
print(f"Server echoed: {data}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment