포트 9999에서 실행되는 소켓 서버 코드가 매우 간단합니다. 서버와 클라이언트를 시작하면 netstat를 통해 서버가 실행되고 있음을 알 수 있습니다.소켓 - 간단한 서버/클라이언트 - socket.error : [Errno 10060]
Traceback (most recent call last):
File "client.py", line 6, in <module>
clisock.connect((host, 9999))
File "C:\Python27\lib\socket.py", line 222, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
내 서버 코드 :
import socket
import sys
import time
srvsock = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
print 'Server Socket is Created'
host = socket.gethostname()
try:
srvsock.bind((host, 9999))
except socket.error , msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
srvsock.listen(5)
print 'Socket is now listening'
while True:
clisock, (remhost, remport) = srvsock.accept()
print 'Connected with ' + remhost + ':' + str(remport)
currentTime = time.ctime(time.time()) + "\r\n"
print currentTime
clisock.send(currentTime)
clisock.close()
srvsock.close()
클라이언트가 7180.
그러나
TCP 192.168.1.117:9999 0.0.0.0:0 LISTENING 7180
의 임시 포트에, 클라이언트의 출력이 오류를 보여줍니다
import socket
clisock = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
print host
clisock.connect((host, 9999))
tm = clisock.recv(1024)
clisock.close()
print tm
문제가 무엇인가
그리고 내 소켓 클라이언트 프로그램은 다음과 같다? 방화벽이나 연결이 끊어지는 원인이 될 수 있습니까?
왜 당신이 사용하는 socket.gethostname()이 아니라 '로컬 호스트'또는 127.0.0.1? socket.gethostname()보다 더 안정적입니다. – Munchhausen