我试图在python中向自己发送一条消息,但是客户端代码给我错误10061服务器正常工作它工作正常,但它突然开始给我错误。我尝试更改端口,但它仍然给我相同的错误
服务器
from socket import *
from datetime import *
def main():
s = socket()
client_socket = None
s.bind(("127.0.0.1",8200))
print "1:time"
print "2:get list of files"
print "3:download file"
print "4:quit"
input()
s.listen(1)
client_socket, client_address = s.accept()
strn=client_socket.recv(4096)
if int(strn[0])>4 or int(strn[0])<1:
print "please send a num between 1-4"
elif int(strn[0])==1:
print datetime.time(datetime.now())
elif int(strn[0])==2:
folder=raw_input("enter the name of the folder")
dir(folder)
client_socket.close()
s.close()
input()
if name == '__main__':
main()
客户
from socket import *
def main():
s = socket()
s.connect(("127.0.0.1",8200))
buf = raw_input()
s.send(buf)
s.close()
input()
if name == '__main__':
main()
错误
Traceback (most recent call last):
File "D:\client.py", line 10, in <module>
main()
File "D:\client.py", line 4, in main
s.connect(("127.0.0.1",8200))
File "C:\Python27\lib\socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10061] No connection could be made because the target machine actively refused it
答案 0 :(得分:0)
10061错误。 在您的情况下,最可能的原因是s.bind和s.connect中的“IP”尝试放置实际的IP或127.0.0.1。它应该工作
答案 1 :(得分:0)
从不介意我修复它的问题是输入是在听之前它让程序停止感谢所有人