diff --git a/python/code/chat_room/Chat_Room_First/client.py b/python/code/chat_room/Chat_Room_First/client.py index a30f7ed..be4f5e9 100644 --- a/python/code/chat_room/Chat_Room_First/client.py +++ b/python/code/chat_room/Chat_Room_First/client.py @@ -83,10 +83,11 @@ class MyFrame(wx.Frame): self.show_text.Clear() def recv_data(self): - if self.state: + while self.state: show_info = self.server_socket.recv(1024).decode('utf-8') self.show_text.AppendText('-' * 40 + '\n' + show_info + '\n') + def send_data(self, event): if self.state: input_data = self.chat_text.GetValue() @@ -98,8 +99,13 @@ class MyFrame(wx.Frame): if __name__ == '__main__': # 初始化app() app = wx.App() - # 创建直接的客户端对象 - frame = MyFrame("lsy").Show() + name = input("请输入你的姓名:") + # 创建直接的客户端对象 + frame = MyFrame(name) + ip = input("请输入ip(默认localhost):") + port = int(input("请输入端口(默认8787):")) + frame.server_host_port = (ip, port) + frame.Show() # 循环刷新显示 app.MainLoop() diff --git a/python/code/chat_room/Chat_Room_First/server.py b/python/code/chat_room/Chat_Room_First/server.py index ec3aa5a..3effdc8 100644 --- a/python/code/chat_room/Chat_Room_First/server.py +++ b/python/code/chat_room/Chat_Room_First/server.py @@ -6,6 +6,7 @@ from threading import Thread import wx import os + class Myserver(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, id=8787, title="Server", pos=wx.DefaultPosition, size=(400, 500)) @@ -140,6 +141,9 @@ if __name__ == '__main__': app = wx.App() # 创建直接的客户端对象 frame = Myserver() + ip = input("请输入ip(默认localhost):") + port = int(input("请输入端口(默认8787):")) + frame.host_port = (ip, port) frame.Show() # 循环刷新显示