Przeglądaj źródła

prepare: zlib compress json vi socket ...

micha 3 lat temu
rodzic
commit
3b842d5a15
3 zmienionych plików z 17 dodań i 9 usunięć
  1. 6 1
      _LibreLightDesk.py
  2. 4 2
      console.py
  3. 7 6
      lib/chat.py

+ 6 - 1
_LibreLightDesk.py

@@ -163,9 +163,14 @@ BEAM  = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
 INT   = ["DIM","SHUTTER","STROBE","FUNC"]
 #client = chat.tcp_sender(port=50001)
 jclient = chat.tcp_sender()#port=50001)
+import zlib
 def jclient_send(data):
     t_start = time.time()
-    jclient.send("\00 "+ json.dumps(data) +"\00 ")
+    jtxt = data
+    jtxt = json.dumps(jtxt)
+    jtxt = jtxt.encode()
+    #jtxt = zlib.compress(jtxt)
+    jclient.send(b"\00 "+ jtxt +b"\00 ")
     print(round((time.time()-t_start)*1000,4),"milis")
     cprint(round(time.time(),4),color="yellow")
 

+ 4 - 2
console.py

@@ -438,8 +438,10 @@ def JCB(data):
             continue
         try:
             jdata = j #jdatas[j]
-            #print(j)
-            cmds = json.loads(jdata)
+            jtxt = jdata
+            #jtxt = zlib.decompress(jtxt) #jtxt.decode())
+            jtxt = str(jtxt,"UTF-8")
+            cmds = json.loads(jtxt)
             for x in cmds:
                 #cprint(int(clock.time()*1000)/1000,end=" ",color="yellow")#time.time())
                 #cprint("json", x,type(x),color="yellow")#,cmds[x])

+ 7 - 6
lib/chat.py

@@ -44,7 +44,8 @@ class tcp_sender(object):
     def send(self,nachricht):
 
         try:
-            self.xs.send(bytes(nachricht+";","utf-8") )
+            #self.xs.send(bytes(nachricht+";","utf-8") )
+            self.xs.send(nachricht+b";" )
         except socket.error as e:
             self.connect()
     def close(self):
@@ -138,10 +139,10 @@ class CMD():
                             
                         nachricht = msg
                         #print(msg)
-                        nachricht = str(nachricht,"utf-8")
-                        nachricht = nachricht.replace(";","")
-                        nachrichten = nachricht.strip().replace("EOB","")
-                        if "client_name:" in nachrichten:
+                        #nachricht = str(nachricht,"utf-8")
+                        nachricht = nachricht.replace(b";",b"")
+                        nachrichten = nachricht.strip().replace(b"EOB",b"")
+                        if b"client_name:" in nachrichten:
                             if sock in clients:
                                 client_nr = clients.index(sock)
                                 clients2[client_nr] = nachrichten
@@ -154,7 +155,7 @@ class CMD():
                             tstamp = time.strftime("%H:%M:%S")
 
                             #print("from:",client_nr,">>>", tstamp , ip, nachrichten.split(";"))
-                            for xx,nachricht in enumerate(nachrichten.split(";")):
+                            for xx,nachricht in enumerate(nachrichten.split(b";")):
                                 cmd = nachricht #.split(" ")
                                 #print(xx,cmd)
                                 cb({"c":client_nr,"cmd":cmd})