Websockets模块-导入其他脚本时出错

时间:2019-02-19 16:12:35

标签: python python-3.x websocket

我正在尝试在Python 3.6中使用websockets模块。我遵循了本教程https://websockets.readthedocs.io/en/stable/intro.html

我可以毫无问题地运行脚本,并且套接字可以通信。

然后,我添加了自己的Python脚本之一的导入,以便使用其功能。

#!/usr/bin/env python

import asyncio
import websockets
import Commands

async def hello(websocket, path):
    recieve = await websocket.recv()
    data = recieve.split()

    if(data[0]=="printAll"):
        Commands.printAll()

def moveForward():
    Commands.move(200)

start_server = websockets.serve(hello, '0.0.0.0', 1235)

asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()

这是我在使用import运行它时得到的错误:

ConnectionRefusedError: [Errno 111] Connection refused

我不明白的事实是,不导入时连接就可以了,但是当我导入自己的脚本时却出现错误(我看不到链接)。

欢迎任何帮助。

0 个答案:

没有答案