我尝试运行有关客户端和服务器的示例代码,但出现了一些错误:
服务器:import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
conn.close()
客户:
^{pr2}$
但是,当客户端正常工作时,错误会出现在服务器上。在Connected by ('192.168.1.102', 11263)
Traceback (most recent call last):
File "C:\Users\Win7_Lab\Desktop\Server.py", line 15, in
conn.sendall("data")
File "C:\Python27\lib\socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
File "C:\Python27\lib\socket.py", line 174, in _dummy
raise error(EBADF, 'Bad file descriptor')
socket.error: [Errno 9] Bad file descriptor
[Finished in 5.3s with exit code 1]
[shell_cmd: python -u "C:\Users\Win7_Lab\Desktop\Server.py"]
[dir: C:\Users\Win7_Lab\Desktop]
[path: C:\Python27\;C:\Python27\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\]
为什么会出现错误?在连接的线路中('192.168.1.102',11263)192.168.1.102是客户端ip,但什么是11263?在