48 lines
1022 B
Python
48 lines
1022 B
Python
import json
|
|
import socket
|
|
import threading
|
|
import time
|
|
|
|
class TCPClient:
|
|
def __init__(self, ip, port):
|
|
self.error_count=0
|
|
self.IPAddress = ip
|
|
self.port = port
|
|
self.client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
self.client_socket.settimeout(5)
|
|
self.connected = False
|
|
|
|
|
|
def CreatConnect(self):
|
|
self.client_socket.connect((self.IPAddress, self.port))
|
|
|
|
|
|
def is_Connect(self):
|
|
try:
|
|
self.client_socket.send(b'')
|
|
return True
|
|
except OSError:
|
|
return False
|
|
|
|
|
|
def run(self):
|
|
while True:
|
|
time.sleep(0.2)
|
|
self.connected = self.error_count > 0
|
|
try:
|
|
#time.sleep(30)
|
|
if (self.send_Command() and self.send_Status()):
|
|
self.error_count = 0
|
|
except:
|
|
self.error_count += 1
|
|
|
|
|
|
def send_Command(self):
|
|
return False
|
|
|
|
def send_Status(self):
|
|
return False
|
|
|
|
|
|
|