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 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):

18
mswp.py
View File

@@ -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

View File

@@ -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

View File

@@ -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()