import socket
tcpsocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
tcpsocket.setsockopt(socket.SOL_SOCKET , socket.SO_REUSEADDR , 1)
tcpsocket.bind(('0.0.0.0',8000))
tcpsocket.listen(2)
print "Server Started "
(client,(ip,port))=tcpsocket.accept()
print "Client connected " + ip
client.send("Welcome to 8000 \n Type in something and see it echoed back")
data="dummy"
while True:
data=client.recv(3096)
if data is None :
break
print "Client Typed in " + data + "\n"
client.send(data)
print "Closing Conneection"
client.close()
print "Shutting down server"
tcpsocket.close()
当我关闭客户端时,我收到以下错误..
Traceback (most recent call last):
File "D:/PYTHON/Client-Server.py", line 18, in <module>
data=client.recv(3096)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
指向
行data=client.recv(3096)
如何顺利断开连接。