为什么python中的socket.send不起作用?

时间:2017-06-01 06:14:22

标签: python sockets flask

我正在尝试使用WiFi连接从raspberry pi上的python flask服务器向nodemcu客户端发送数据。我成功建立了TCP连接。但是,sock.send不能在特定功能下工作。如果我在这个函数之外使用sock.send它可以正常工作。有人可以查看我的代码。

def flask():
    connection() #This function establish the connection successfully. I have not included the content of function just for simplicity. No problem with this part.
    sock.send('thanks for connecting') #This works fine.
    app = Flask(__name__, template_folder='Templates')
    @app.route('/')
    def index():
        return render_template('index.html')
    @app.route('/message')
    def msg():
        a = request.args.get('a') #This the variable obtained from web page using j Query. I want to send this value to nodemcu client. 
        sock.send(a) #This is NOT WORKING
        print(a) #But the value is printed on python terminal.
        return render_template('index.html')

0 个答案:

没有答案