two package network fucntion uncompleted"

This commit is contained in:
2019-12-15 12:30:06 +08:00
parent dfd5369114
commit 5578131df7
4 changed files with 29 additions and 20 deletions

View File

@@ -1,4 +1,3 @@
import json
import threading import threading
import json import json
import time import time
@@ -15,13 +14,14 @@ class Jsondata:
self.thread = threading.Thread(target=self.run, args=()) self.thread = threading.Thread(target=self.run, args=())
self.thread.start() 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(): if key in self.raw_jsondata.keys():
return self.raw_jsondata[key] return self.raw_jsondata[key]
else: else:
print('Error: could not find key value in file "config.json"\n' if output:
'Please set the key "%s" in file "config.json"\n' print('Error: could not find key value in file "config.json"\n'
'Or MSW will set it as %s' % (key, or_value)) 'Please set the key "%s" in file "config.json"\n'
'Or MSW will set it as %s' % (key, or_value))
return or_value return or_value
def get(self, key): def get(self, key):

18
mswp.py
View File

@@ -1,3 +1,6 @@
from config import jsondata
class Datapack: class Datapack:
def __init__(self, method='post', app='all', version='msw/1.0', head={}, body=b'', check_head=True): def __init__(self, method='post', app='all', version='msw/1.0', head={}, body=b'', check_head=True):
self.method = method self.method = method
@@ -30,17 +33,8 @@ class Datapack:
i, ii = line.split(': ') i, ii = line.split(': ')
self.head[i] = ii self.head[i] = ii
def is_enough(self): def split_dp_data(data):
body_length = len(self.body) pass
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 is_complete(self):
pass # here needs to add more function

View File

@@ -56,6 +56,7 @@ class Netrecv:
self.thread.start() self.thread.start()
self.connection_list = [] self.connection_list = []
self.connection_process_thread_list =[] self.connection_process_thread_list =[]
self.un_enougth_list = []
def check_accpet_connection(self): def check_accpet_connection(self):
while True: while True:
@@ -75,7 +76,7 @@ class Netrecv:
dp = Datapack(check_head=False) dp = Datapack(check_head=False)
dp.encode_data = data dp.encode_data = data
dp.decode() dp.decode()
send_queue.put(dp)
class Netlist: # contain net list and network controller class Netlist: # contain net list and network controller

View File

@@ -2,14 +2,28 @@ import socket
data = '''post log msw/1.0 data = '''post log msw/1.0
from: network 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() data = data.encode()
data2 = data2.encode()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 3900)) s.connect(('127.0.0.1', 3900))
s.sendall(data) s.sendall(data)
print(data) s.sendall(data2)
s.close() s.close()