-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from DavidBerger98/multi-server-example
docs(examples): Multi-server example
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |