From 2bfbb8862bfd4d8ee796bc2f40af32b0dc65a295 Mon Sep 17 00:00:00 2001 From: lsy2246 Date: Fri, 12 Apr 2024 00:56:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=8F=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E4=BF=AE=E6=94=B9,=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/test/Cilent/Login.py | 21 +++- python/test/Cilent/Session_server.py | 60 ++++++------ python/test/Cilent/__init__.py | 11 +-- .../Cilent/__pycache__/Login.cpython-312.pyc | Bin 12701 -> 13732 bytes .../Session_server.cpython-312.pyc | Bin 3543 -> 3041 bytes .../__pycache__/__init__.cpython-312.pyc | Bin 976 -> 634 bytes python/test/Server/Session_client.py | 29 ++++++ python/test/Server/__init__.py | 7 ++ python/test/StartClient.py | 2 +- python/test/StartServer.py | 4 + python/test/test.py | 91 ++++++++++-------- 11 files changed, 141 insertions(+), 84 deletions(-) create mode 100644 python/test/Server/Session_client.py create mode 100644 python/test/Server/__init__.py create mode 100644 python/test/StartServer.py diff --git a/python/test/Cilent/Login.py b/python/test/Cilent/Login.py index f42ec33..060ca5b 100644 --- a/python/test/Cilent/Login.py +++ b/python/test/Cilent/Login.py @@ -1,7 +1,8 @@ import wx import threading import time -from tkinter import messagebox + +from .Session_server import * class LoginFrame(wx.Frame): @@ -78,9 +79,10 @@ class LoginFrame(wx.Frame): self.Layout() -class LoginPanel(wx.Panel): +class LoginPanel(wx.Panel, Session_server): def __init__(self, parent): super().__init__(parent) + Session_server.__init__(self) # 主盒子 main_box = wx.BoxSizer(wx.VERTICAL) @@ -119,16 +121,25 @@ class LoginPanel(wx.Panel): bottom_box = wx.BoxSizer(wx.VERTICAL) # 登录按钮 login_box = wx.BoxSizer(wx.VERTICAL) # 使用垂直盒子布局 - login_label = wx.Button(self, size=(200, 50), label='登录') + self.login_label = wx.Button(self, size=(200, 50), label='登录') login_box.AddStretchSpacer() # 添加一个可伸缩的空间,将登录按钮推到垂直中间 - login_box.Add(login_label, 0, wx.ALIGN_CENTER_HORIZONTAL) # 将登录按钮添加到垂直盒子中 + login_box.Add(self.login_label, 0, wx.ALIGN_CENTER_HORIZONTAL) # 将登录按钮添加到垂直盒子中 login_box.AddStretchSpacer() # 再次添加一个可伸缩的空间,将登录按钮推到垂直中间 bottom_box.Add(login_box, 1, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL) # 将垂直盒子添加到底部盒子中,设置垂直和水平居中对齐 main_box.Add(bottom_box, 1, wx.EXPAND) # 将底部盒子添加到主盒子中,使其填满剩余空间 + # 按钮绑定 + self.Bind(wx.EVT_BUTTON, self.send_login_button, self.login_label) + self.SetSizer(main_box) - + def send_login_button(self, event): + account = self.account_text.GetValue().strip() + password = self.password_text.GetValue().strip() + content = {'account': account, 'password': password} + target = "服务器" + genre = "登录" + self.send_server(genre=genre, target=target, content=content) class RegisterPanel(wx.Panel): diff --git a/python/test/Cilent/Session_server.py b/python/test/Cilent/Session_server.py index 11ba85a..44c60c9 100644 --- a/python/test/Cilent/Session_server.py +++ b/python/test/Cilent/Session_server.py @@ -1,47 +1,43 @@ -import string import time import socket -from threading import Thread -import random import json +import threading class Session_server: - def __init__(self, ip_socker, port_socker): - self.ip_socker = ip_socker - self.port_socker = port_socker - self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + def __init__(self): + self.ip_socker = "127.0.0.1" + self.port_socker = 8000 + self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server_status = False # 服务器状态 - def Link_server(self): - Verification_code = "" - for _ in range(20): - if random.choice([True, False]): - Verification_code += str(random.randint(0, 9)) - else: - Verification_code += random.choice(string.ascii_letters) - data = {"genre": "test", "source": "Link_server", "data": Verification_code, - "datetime": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} - data_json = json.dumps(data) - self.server_socket.sendto(data_json.encode("utf-8"), (self.ip_socker, self.port_socker)) - receive_content_json = self.server_socket.recv(1024).decode('utf-8') - receive_content = json.loads(receive_content_json) - if receive_content["data"] == Verification_code: - self.server_status = True # 服务器状态 - Receive_server_Thread = Thread(target=self.Receive_server) - Receive_server_Thread.daemon = True - Receive_server_Thread.start() + self.link_server_Thread = threading.Thread(target=self.link_server) + self.link_server_Thread.start() + self.receive_server_Thread = threading.Thread(target=self.receive_server) - def Receive_server(self): + def link_server(self): + while not self.server_status: + try: + time.sleep(1) + self.server_socket.connect((self.ip_socker, self.port_socker)) + self.server_status = True + if not self.link_server_Thread.is_alive(): + self.receive_server_Thread.start() + except: + self.server_status = False + + def receive_server(self): while self.server_status: - receive_content_json = self.server_socket.recv(1024).decode('utf-8') # 追加接收到的数据 - receive_content = json.loads(receive_content_json) - print(receive_content) + try: + receive_content_json = self.server_socket.recv(1024).decode('utf-8') # 追加接收到的数据 + receive_content = json.loads(receive_content_json) + except: + self.server_status = False - def Send_server(self, genre, source, content): + def send_server(self, genre, target, content): if self.server_status: - data = {"genre": genre, "source": source, "data": content, + data = {"genre": genre, "target": target, "data": content, "datetime": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} data_json = json.dumps(data) - self.server_socket.sendto(data_json.encode("utf-8"), (self.ip_socker, self.port_socker)) + self.server_socket.send(data_json.encode("utf-8")) diff --git a/python/test/Cilent/__init__.py b/python/test/Cilent/__init__.py index ec0fe5b..0edc19e 100644 --- a/python/test/Cilent/__init__.py +++ b/python/test/Cilent/__init__.py @@ -3,13 +3,10 @@ from .Session_server import * class Client_main(LoginFrame, Session_server): - def __init__(self, ip_socker, port_socker): - Session_server.__init__(self, ip_socker, port_socker) + def __init__(self): + Session_server.__init__(self) # 与服务器会话 LoginFrame.__init__(self) - Session_server.Link_server(self) - # 主页按键绑定 - def Sign_Account(self, event): - if self.GetParent().server_status: - pass + + diff --git a/python/test/Cilent/__p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G|7yHSve`EuFKUUfQbotg&J4jBh` zX+Hcu`CHo_;{6x6!f2)O(0dzy*|>x6PTX1CX*^bL>ilT#!QoFs_d?s;c7G{8T#Aio zP4L_KFHl|nc=5x<&j$5ZCbd^4OR?9rCiv~#^;2WJbtoA5WVra-xk`IvYkG6K*gO1% z`sKTyzgs$YvDE(NPj0ShmMic-wzS@Ub{`n3+ld3&DVK1u6GS+ zT>}qKm%7ew<1e$HXTQbz%sbl5JH=sX$M=VFII4&HwQ#>49@N5v57komH9b70g~z^{ zEQP0vzV=EmwAH)WTa3M03Jw(-%YopXK`qc#>^c1?aJt+XD~#`mp-Ok}!)|?GLK~Ra z={{c+JIlvT0NoLfmc>q8Jfew59*gl^KN8Q7W;nxV3IvS``nUfbklPeCpg-8i??GOD zht%rQc13oim}AMCwu?iJ)-E4Vh-hA#Ep0FyY-d{ z1MV3T205Yd8TVQ_K$C}@pybz-P#hu@Pz+%ea#D@E&G;v0sQgtRtlC=vIslRz9R~vR z+34=3i!K6z7;Sh#Z-_i7~SsikB&8hRbov^-*F!0^=SlPJ&cQi@M>h zVxS3<$YDt|IvYpX;v`OMb+jNndZmnkj9MZ@~Q7NYp)|@0%Y`c it3-k9x;c*f9@T%30zm(X+AaP+o*qu-_7J6}k^cg?3eBVd diff --git a/python/test/Cilent/__pycache__/__init__.cpython-312.pyc b/python/test/Cilent/__pycache__/__init__.cpython-312.pyc index 74814e935bba5975fee13464b47d20b01c30d0bc..986bdf993994418f17fb36bfc67d6c57a92d2014 100644 GIT binary patch delta 324 zcmcb>{)>h0G%qg~0}$-tlSq5TFp)3MMhM88&XCFw#hAhn#gxL>!Vtw=$)w4Ai`zLT zGc~UyJ~uHlFPRaf2@05jGzfo=n7B`MvNa>u#E)9+l?}WRL2E|d KR|X&htQP?7&_e70 literal 976 zcmZ`&zfTlF6n?XNivxSd4}%1~7)~k|6JlXSl*B+JCWM&KT`rkyb_d+!*ga?FNS0hd zK}@W)J4#x-nD}oPD-;9STxVrRJZ-3)x4Q?|IK`W9-uu2cZ{M5!S}Ki!UN67QY<(mE zKk+bFBRS|l)}RAE_@n`!43Z&&$bdEQjYIHFZgA2qWQwX87aZ%C&Ib-j$by$AN;mZ4 z>d$J^0S;B-L)GxfAyiGwRV~D(Q%LNUM!-YGcHJQK%v6#YOK*7YztyG#D)VYvA7~3D3X5Qqzbq%jU8*Z2}oRAG&@%Sc}GKfMZx!B_(p^OD#pcqTW z)}!qpd?DOjp4jU_xRX;HGbu>k*h)r&CXM{s`;*RYhL8@ zS~FI!qp+s9RJE0$p}SNYT(#JY#i$nTPY<(Sfiw0ug-N2_P_K^mVwrSr#6e$a<~tpU$Kn=i!a6qYpTKpX0V!44RD@8-BZtjv9a z#1MnP-a1Ayy2jNjSLjbkN?H4uRIX}C#}GwLNi4pngAx-}Dq;d%#m!(lWY0Y>YK3Zl zcKCybBPGq1_p~{H3wz@I^1J2lcKO_PzS+)2aq`lH;)0me;SI;ak%f9lI5Ng|Bfr%^ zTx9G`%WY(lw7uev7Mwt;ON$ZsDpP|%V#$Z_+b}JsKW