最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How To Receive Data From Web socket's Using Python - Stack Overflow

programmeradmin1浏览0评论

So basically I want to create a Websocket server using Python, on my last question about this I said I didn't want to use external libraries, but that wasn't received very well. So how can you do it using external libraries? I have already figured out the Websocket send using Javascript, but I need a Python Websocket server. So can someone give me a working example with Python 3.6?

So basically I want to create a Websocket server using Python, on my last question about this I said I didn't want to use external libraries, but that wasn't received very well. So how can you do it using external libraries? I have already figured out the Websocket send using Javascript, but I need a Python Websocket server. So can someone give me a working example with Python 3.6?

Share Improve this question asked Jul 10, 2017 at 1:06 user7873306user7873306
Add a ment  | 

1 Answer 1

Reset to default 5

the following es from https://websockets.readthedocs.io/en/stable/intro.html ... which was the second link i think i found when i googled "python3 websockets"

#!/usr/bin/env python

import asyncio
import websockets

async def hello(websocket, path):
    name = await websocket.recv()
    print("< {}".format(name))

    greeting = "Hello {}!".format(name)
    await websocket.send(greeting)
    print("> {}".format(greeting))

start_server = websockets.serve(hello, 'localhost', 8765)

asyncio.get_event_loop().run_until_plete(start_server)
asyncio.get_event_loop().run_forever()
发布评论

评论列表(0)

  1. 暂无评论