问题
异常的原因是什么?
客户端是否导致任何错误?
如果可能,请解释其他错误。
背景
我正在创建一个 Python GUI 套接字服务器。当客户端连接到我的服务器时,GUI 窗口将打开(我仍在处理此问题)。但是,当客户端连接时,我收到一个错误:
Unhandled exception in thread started by <function clientthread at 0x10246c230>
由于实际脚本相当长,我提供了一个 pastebin 链接。
这是线程代码。s
是我的socket
对象的名称。
def clientthread(s):
#Sending message to connected client
#This only takes strings (words
s.send("Welcome to the server. Type something and hit enter\n")
#loop so that function does not terminate and the thread does not end
while True:
#Receiving from client
data = s.recv(1024)
if not data:
break
s.sendall(data)
print data
s.close()
追溯
感谢莫腾的建议。这是追溯。
Socket Created
Socket Bind Complete
Socket now listening
Connected
Traceback (most recent call last):
File "/Users/BigKids/Desktop/Coding/Python 2/Sockets/Function/Server GUI Alpha Function.py", line 80, in clientthread
s.send("Welcome to the server. Type something and hit enter\n")
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 170, in _dummy
raise error(EBADF, 'Bad file descriptor')
error: [Errno 9] Bad file descriptor
就个人而言,我相信许多错误是由于 GUI 造成的。
谢谢!