python accept函数_Python,accept()函数出现套接字错误

我尝试运行有关客户端和服务器的示例代码,但出现了一些错误:

服务器: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?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值