stuff
This commit is contained in:
parent
c1888e1cc3
commit
fa9fa1746c
3 changed files with 12 additions and 8 deletions
|
@ -2,12 +2,12 @@
|
|||
import pdb
|
||||
from mitmproxy import ctx
|
||||
import threading
|
||||
from queue import Queue
|
||||
from queue import Queue, Empty
|
||||
import time
|
||||
import zmq
|
||||
import json
|
||||
|
||||
NO_MSG {"msg": None}
|
||||
NO_MSG = {"msg": None}
|
||||
INIT_MSG = {"msg": "init"}
|
||||
ACK_MSG = {"msg": "ack"}
|
||||
PING_MSG = {"msg": "ping"}
|
||||
|
@ -30,7 +30,7 @@ def get_msg(socket):
|
|||
if msg:
|
||||
return json.loads(msg)
|
||||
except json.JSONDecodeError:
|
||||
print("malformed message received '{msg}'")
|
||||
print(f"malformed message received {msg}")
|
||||
|
||||
return NO_MSG
|
||||
|
||||
|
@ -68,7 +68,10 @@ def networking(q):
|
|||
timer = time.monotonic()
|
||||
|
||||
if not a:
|
||||
a = q.get(block=False)
|
||||
try:
|
||||
a = q.get(block=False)
|
||||
except Empty:
|
||||
pass
|
||||
if a:
|
||||
send_msg(a, socket)
|
||||
msg = get_msg(socket)
|
||||
|
|
|
@ -19,12 +19,12 @@ void NetworkThread::process() {
|
|||
|
||||
while(true){
|
||||
bool connected = false;
|
||||
while(!connected) {
|
||||
sock.send(zmq::str_buffer("{'type': 'init'}"), zmq::send_flags::dontwait);
|
||||
while(!connected) {
|
||||
sock.send(zmq::buffer(INIT_MSG_STR.c_str(), INIT_MSG_STR.length()), zmq::send_flags::dontwait);
|
||||
zmq::message_t msg;
|
||||
const auto ret = sock.recv(msg, zmq::recv_flags::dontwait);
|
||||
if(ret) {
|
||||
if(msg.to_string() == "{'type': 'ack'}") {
|
||||
if(msg.to_string() == ACK_MSG_STR) {
|
||||
connected = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#include <QObject>
|
||||
#include <includes.h>
|
||||
|
||||
const auto INIT_MSG = R"({"msg": "init"})"_json;
|
||||
const std::string INIT_MSG_STR = R"({"msg": "init"})";
|
||||
const std::string ACK_MSG_STR = R"({"msg": "ack"})";
|
||||
|
||||
class NetworkThread : public QObject
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue