I am trying to implement something like a chat server and/or fast computation progress exchange from Julia code (to login from anywhere with the browser). The first search gave me WebSockets.jl and HTTP.jl for websockets, but i found docs and examples to be very hard to utilize to build a simple websockets server.
I actually found something very close to what i want in Python: https://github.com/prziborowski/npmud
The problem is that i do not want to use Python (well, this is why i am using Julia after all).
Here is basically the code that does all the job in Python:
import asyncio import websockets async def consumer_handler(user): while True: try: message = await user._ws.recv() await user.process_input(message) consumer(message) except websockets.exceptions.ConnectionClosed: await user.exit() async def producer_handler(user): while True: message, empty = await user.get_message() await user.send(message) if empty: await user.prompt() async def handler(websocket, path): newuser = users.User(websocket) if not await newuser.send_welcome(): return users.add(newuser) try: consumer_task = asyncio.ensure_future(consumer_handler(newuser)) producer_task = asyncio.ensure_future(producer_handler(newuser)) done, pending = await asyncio.wait( [consumer_task, producer_task], return_when=asyncio.FIRST_COMPLETED, ) for task in pending: task.cancel() finally: try: # Try to safely logout user await newuser.exit() except: pass start_server = websockets.serve(handler, '0.0.0.0', 4000) loop = asyncio.get_event_loop() loop.run_until_complete(start_server) logger.info("Server started.") try: loop.run_forever() except KeyboardInterrupt: logger.info('Shutting down server.')
What would be your suggestions to build the same thing from Julia?
Can i use existing Julia packages to implement similar websockets server?
Do you know any examples/tutorials with existing packages (well, may be i just did not look deep enough?)
Or may be some parts of Python routines could be called from Julia using PyCall?
Any suggestions are welcomed. Thank you in advance,