C로 작성된 서버와 상호 작용하는 asyncore 클라이언트가 있습니다. 서버가 연결을 닫고 연결을 계속 시도 할 때이를 감지 할 수 있어야합니다 다시 사용할 수있게 될 때까지 여기에 내가 가지고있는 코드는 다음과 같습니다. 이것은 다른 스레드 모듈에서 실행되는 다른 스레드 모듈 (ReceiverBoard)을 시작하는 asyncore 클라이언트입니다. 클래스 DETClient (asyncore.dispatcher) :서버와의 비동기 연결을 다시 설정하는 방법 (해결됨)
내 첫 번째 문제는 연결이 될 때까지 내가 소켓을 통해 (ANSI C 개발) 서버에 연결 재 시도를 유지하기 위해 (위) 클라이언트를 원이었다buffer = ""
t = None
def __init__(self, host, port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host,port))
self.host=host
self.port=port
self.t = ReceiverBoard(self)
self.t.start()
def sendCommand(self, command):
self.buffer = command
def handle_error(self):
self.t.stop()
self.close()
def handle_write(self):
sent=self.send(self.buffer.encode())
self.buffer=""
def handle_read(self):
##there is code here to parse the received message and call the appropriate
##method in the threaded module ReceiverBoard
.
HAJ 에산 코드입니다, 여기에 코드를 게시하시기 바랍니다 당신이 시도 한 내용을 추가하십시오. – AliBZ
haj ali, 고맙습니다 만 만 명. 도와 주셔서 감사합니다. –
하하 알리, 고마워. 실수로 해결책을 찾았습니다. –