局域网连接有问题

This commit is contained in:
lsy2246 2024-04-03 15:50:27 +08:00
parent 51d41d9ffc
commit 89e3036505
2 changed files with 13 additions and 3 deletions

View File

@ -83,10 +83,11 @@ class MyFrame(wx.Frame):
self.show_text.Clear() self.show_text.Clear()
def recv_data(self): def recv_data(self):
if self.state: while self.state:
show_info = self.server_socket.recv(1024).decode('utf-8') show_info = self.server_socket.recv(1024).decode('utf-8')
self.show_text.AppendText('-' * 40 + '\n' + show_info + '\n') self.show_text.AppendText('-' * 40 + '\n' + show_info + '\n')
def send_data(self, event): def send_data(self, event):
if self.state: if self.state:
input_data = self.chat_text.GetValue() input_data = self.chat_text.GetValue()
@ -98,8 +99,13 @@ class MyFrame(wx.Frame):
if __name__ == '__main__': if __name__ == '__main__':
# 初始化app() # 初始化app()
app = wx.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() app.MainLoop()

View File

@ -6,6 +6,7 @@ from threading import Thread
import wx import wx
import os import os
class Myserver(wx.Frame): class Myserver(wx.Frame):
def __init__(self): def __init__(self):
wx.Frame.__init__(self, None, id=8787, title="Server", pos=wx.DefaultPosition, size=(400, 500)) 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() app = wx.App()
# 创建直接的客户端对象 # 创建直接的客户端对象
frame = Myserver() frame = Myserver()
ip = input("请输入ip(默认localhost):")
port = int(input("请输入端口(默认8787):"))
frame.host_port = (ip, port)
frame.Show() frame.Show()
# 循环刷新显示 # 循环刷新显示