Hello all,
I am writing a script to know the status of a networked device. A small API allow minimum integration.
My script is basically opening a socket and buffering the data from this socket in a while loop.
It seems that each time the loop is going on, I read the same data via s.recv(1024) and therefore duplicate my output.
Is there another method to avoid this?
Extract of my code
where the device is only changing status 3 times, I should have :
Any idea of what socket module I should use to avoid that? Alternatively, is there any better way to do this?
I am writing a script to know the status of a networked device. A small API allow minimum integration.
My script is basically opening a socket and buffering the data from this socket in a while loop.
It seems that each time the loop is going on, I read the same data via s.recv(1024) and therefore duplicate my output.
Is there another method to avoid this?
Extract of my code
import socket import time def run(self): def timer(host,T,Fmax,ms1): ms1=self.ms1 s.settimeout(T) F=1 while True: #Ctrl+C to interrupt the loop time.sleep(0.5) try: data=s.recv(1024) data=data.decode() data=data.strip() except socket.timeout: F+=1 if F==Fmax or F>Fmax: breakoutput is like :
Quote:Status 1
Status 1
Status 1
Status 1
Status 2
Status 2
Status 3
where the device is only changing status 3 times, I should have :
Quote:Status 1
Status 2
Status 3
Any idea of what socket module I should use to avoid that? Alternatively, is there any better way to do this?