Skip to content

Commit

Permalink
Merge pull request #125 from DavidBerger98/multi-server-example
Browse files Browse the repository at this point in the history
docs(examples): Multi-server example
  • Loading branch information
jourdain authored Oct 16, 2022
2 parents b480332 + 78008d9 commit 7c0d21b
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions examples/00_howdoi/mutli-server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
r"""
Multi-server setup
"""

import asyncio

from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify


server1 = get_server("server1")
state1 = server1.state
state1.trame__title = "Server1"

server2 = get_server("server2")
state2 = server2.state
state2.trame__title = "Server2"


def send_to_server1(message):
with state1:
state1.received = message


def send_to_server2(message):
with state2:
state2.received = message


with SinglePageLayout(server1) as layout:
layout.title.set_text("Server1")

with layout.content:
with vuetify.VCard(classes="pa-4"):
vuetify.VTextField(
v_model=("message", "Hi from server 1"),
)
vuetify.VBtn(
"Send message to server 2",
click=(send_to_server2, "[message]"),
)
vuetify.VTextField(readonly=True, v_model=("received", "<message here>"))

with SinglePageLayout(server2) as layout:
layout.title.set_text("Server2")

with layout.content:
with vuetify.VCard(classes="pa-4"):
vuetify.VTextField(
v_model=("message", "Hi from server 2"),
)
vuetify.VBtn(
"Send message to server 1",
click=(send_to_server1, "[message]"),
)
vuetify.VTextField(
readonly=True,
v_model=("received", "<message here>"),
)


if __name__ == "__main__":
task1 = server1.start(exec_mode="task", port=8080)
task2 = server2.start(exec_mode="task", port=8081)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(task1, task2))

0 comments on commit 7c0d21b

Please sign in to comment.