From 5578131df7707b6e119ed98249efc28d4c86e983 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Sun, 15 Dec 2019 12:30:06 +0800 Subject: [PATCH] two package network fucntion uncompleted" --- config.py | 10 +++++----- mswp.py | 18 ++++++------------ plugins/net.py | 3 ++- test_file.py | 18 ++++++++++++++++-- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/config.py b/config.py index 227aa1c..d3e2706 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,3 @@ -import json import threading import json import time @@ -15,13 +14,14 @@ class Jsondata: self.thread = threading.Thread(target=self.run, args=()) self.thread.start() - def try_to_read_jsondata(self, key, or_value, template=0): + def try_to_read_jsondata(self, key, or_value, template=0, output=True): if key in self.raw_jsondata.keys(): return self.raw_jsondata[key] else: - print('Error: could not find key value in file "config.json"\n' - 'Please set the key "%s" in file "config.json"\n' - 'Or MSW will set it as %s' % (key, or_value)) + if output: + print('Error: could not find key value in file "config.json"\n' + 'Please set the key "%s" in file "config.json"\n' + 'Or MSW will set it as %s' % (key, or_value)) return or_value def get(self, key): diff --git a/mswp.py b/mswp.py index 63796e1..cb1d7ed 100644 --- a/mswp.py +++ b/mswp.py @@ -1,3 +1,6 @@ +from config import jsondata + + class Datapack: def __init__(self, method='post', app='all', version='msw/1.0', head={}, body=b'', check_head=True): self.method = method @@ -30,17 +33,8 @@ class Datapack: i, ii = line.split(': ') self.head[i] = ii - def is_enough(self): - body_length = len(self.body) - head_length = int(self.head['length']) - if head_length == body_length: - return True - elif head_length > body_length: - return False - else: - print("Error: length is larger than the body") - raise IOError +def split_dp_data(data): + pass + - def is_complete(self): - pass # here needs to add more function diff --git a/plugins/net.py b/plugins/net.py index 4c5d8f4..2026e71 100644 --- a/plugins/net.py +++ b/plugins/net.py @@ -56,6 +56,7 @@ class Netrecv: self.thread.start() self.connection_list = [] self.connection_process_thread_list =[] + self.un_enougth_list = [] def check_accpet_connection(self): while True: @@ -75,7 +76,7 @@ class Netrecv: dp = Datapack(check_head=False) dp.encode_data = data dp.decode() - send_queue.put(dp) + class Netlist: # contain net list and network controller diff --git a/test_file.py b/test_file.py index 4877fe8..6ff2750 100644 --- a/test_file.py +++ b/test_file.py @@ -2,14 +2,28 @@ import socket data = '''post log msw/1.0 from: network +flag: aaaaa +length: 15 +part_length: 7 +num: 1 -hello, network!''' +hello, ''' + +data2 = '''post log msw/1.0 +from: network +flag: aaaaa +part_length: 8 +length: 15 +num: 2 + +network!''' data = data.encode() +data2 = data2.encode() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', 3900)) s.sendall(data) -print(data) +s.sendall(data2) s.close()