I as a tcp server need to connect a PLC as a tcp client what never send any messages to me and meantime i need to send data to tell the plc to do some commands. Now I have problem about how to connect the tcp client when it closed the connection. Now my thinking is to create a main thread what to send some important data to the plc and a sub thread what to repeat keep connection for the plc. Everytime the tcp server must send data in 0.5 seconds. The plc have 0.5 seconds to get these data in industry and then it will into a next loop. The main thread is a image classification model and only haves.0.5 seconds to predict a image. For the sub thread,how to keep the tcp connection when the plc close connection actively? What is a PLC ? That is the working environment with the PLC My code is here
main thread code
def send_data(self, data, tcpCilSock):
self.setting.send_data = data.encode('utf-8')
respMsg = self.setting.send_data
tcpCilSock.sendall((bytes(respMsg)))
log.info(data)
def run_thread(self):
while True:
try:
if setting.is_tcp_client:
tcpSvr.send_data(send_data, setting.tcpCilSock)
break
except:
log.info('main thread is failed')
a sub thread
def run(self):
while True:
try:
self.tcpSvr.send_data(content, setting.tcpcilsock)
except:
log.info('sub thread is failed')