-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
运行TCP服务器时报错 #4
Comments
完整的修改后的Tcp.py代码: from PySide2.QtCore import Signal from . import StopThreading class TcpLogic:
|
另外,Network/_init_py 也需要修改,修改后的完整代码: from .Tcp import TcpLogic class NetworkLogic(TcpLogic, UdpLogic, WebLogic): class MainWindow的初始化也需要相应修改: 添加了 NetworkLogic.init(self) 这样做的原因是之前的代码MainWindow没有继承到TcpLogic的self.client_socket_list,导致了报错 |
Traceback (most recent call last):
File "C:\Users\20762\anaconda3\envs\databasetry\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\20762\anaconda3\envs\databasetry\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\20762\Downloads\NetAssist_PyQt-main\src\Network\Tcp.py", line 57, in tcp_server_concurrency
for client, address in self.client_socket_list:
AttributeError: 'MainWindow' object has no attribute 'client_socket_list',报错原因是:Tcp.py中的tcp_server_concurrency函数出错,具体如下:
for client, address in self.client_socket_list:
try:
recv_msg = client.recv(4096)
except Exception as ret:
pass
else:
if recv_msg:
info = recv_msg.decode("utf-8")
msg = f"来自IP:{address[0]}端口:{address[1]}:"
self.tcp_signal_write_msg.emit(msg)
self.tcp_signal_write_info.emit(info, self.InfoRec)
如上代码段,应在前面的else条件语句下,而非与else平级
修改后的完整tcp_server_concurrency代码如下:
def tcp_server_concurrency(self):
"""
功能函数,供创建线程的方法;
使用子线程用于监听并创建连接,使主线程可以继续运行,以免无响应
使用非阻塞式并发用于接收客户端消息,减少系统资源浪费,使软件轻量化
The text was updated successfully, but these errors were encountered: