Last active
March 28, 2023 09:15
-
-
Save wonglok/99896631fc2bd87820a410dc2eb26598 to your computer and use it in GitHub Desktop.
websocket with blender
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
import asyncio | |
import websockets | |
async def echo(websocket): | |
async for message in websocket: | |
await websocket.send(message) | |
async def main(): | |
async with websockets.serve(echo, "localhost", 8173): | |
await asyncio.Future() # run forever | |
asyncio.run(main()) |
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
export default function WebSocketPage() { | |
return ( | |
<div> | |
{/* */} | |
<button | |
onClick={() => { | |
// | |
let ws = new WebSocket(`ws://localhost:8173`) | |
ws.addEventListener('open', (ev) => { | |
ws.send('to-blender-123') | |
}) | |
ws.addEventListener('message', (ev) => { | |
console.log('receive data from blender', ev.data) | |
}) | |
}}> | |
Open WebSocket to Blender | |
</button> | |
{/* */} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment