Skip to content

Commit

Permalink
[fixed] server main
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsimonart committed Feb 28, 2018
1 parent 28f91d8 commit d475d24
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GLM
Submodule GLM updated from cfdbd5 to b00f0f
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
app = Flask(__name__)
app.debug = True

PLUGIN_DIRECTORY = "./GLM/source/" + glm.PLUGIN_PREFIX + "/"

server_addr = 'localhost'
server_port = 9999

Expand Down
7 changes: 1 addition & 6 deletions scheme.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
handle_web_client(): !transmit

* send "a:client_connected" -> web_client
* web_client -> recv event

# Read events in event_read
handle_plugin
48 changes: 43 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from GLM import glm
from sys import argv
from time import sleep
from queue import Queue
from queue import Queue, Empty
import multiprocessing
from GLM.source.libs.rainbow import msg
import traceback
Expand Down Expand Up @@ -45,11 +45,49 @@ def handle_plugin(plugin, plugin_id, transmit):
"""
client.send(b"a:client_connected")
while transmit:
status = plugin.recv(BUFFSIZE).decode()
response = plugin.recv(BUFFSIZE).decode()
if not response or response == "EOT": # Single receive
transmit = False

# event_queue get REFRESH
elif response == "READY":
try:
event = event_queue.get_nowait() # Waiting for event
except Empty:
event = None

# refresh phase
if event == "REFRESH":
plugin.send(json.dumps(event).encode())
data_json = plugin.recv(BUFFSIZE).decode()
if not data_json or data_json == "EOT":
transmit = False
else:
data = json.loads(data_json)
data_list[2] += 1
data_list[1] = data

# event phase
elif type(event) == dict:
plugin.send(json.dumps(event).encode())
status = plugin.recv(BUFFSIZE).decode()
if not status or status == "EOT":
transmit = False
elif status == "RECEIVED":
# Event received
pass

# event_queue get DICT type
else:
# Unknown event
plugin.send(json.dumps("UNKNOWN").encode())
status = plugin.recv(BUFFSIZE).decode()
if not status or status == "EOT":
transmit = False
elif status == "RETRYING":
# Plugin is trying again
pass

# Reset event !!!
event = None

# while transmit:
# # Check if plugin is outdated
Expand Down Expand Up @@ -139,7 +177,7 @@ def handle_web_client(web_client, web_client_id, transmit, plugin_loader):
while data_state >= data_list[2]:
# Event is waiting for refresh
sleep(0.2)
web_client.send(data_list[1].encode())
web_client.send(json.dumps(data_list[1]).encode())

# Sending events phase
event_test = event_read.pop("WRITE", None)
Expand Down

0 comments on commit d475d24

Please sign in to comment.