-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (27 loc) · 820 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask,render_template, request, json
import zmq
import time
app = Flask(__name__)
context = zmq.Context()
# Socket to talk to server
print("Connecting to ZMQ server…")
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
command = request.json['command']
print(request.json)
print("Got message from client to : ", command)
print("Sending message to console..")
socket.send_string(command)
# Get the reply.
message = socket.recv()
print("Received reply [ %s ]" % message)
return render_template('index.html')
@app.route('/poll', methods=['GET'])
def poll():
time.sleep(1)
return "pollinggg"
if __name__ == "__main__":
app.run(debug=True)