edl/Example/Library/tcpclient.py
2020-12-22 22:19:37 +01:00

29 lines
925 B
Python
Executable file

import socket
from binascii import hexlify
class tcpclient():
def __init__(self, port):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ("localhost", port)
print("connecting to %s port %s" % server_address)
self.sock.connect(server_address)
def sendcommands(self,commands):
try:
for command in commands:
self.sock.sendall(bytes(command, 'utf-8'))
data=""
while not "<ACK>" in data and not "<NAK>" in data:
tmp = self.sock.recv(4096)
if tmp == b"":
continue
try:
data += tmp.decode('utf-8')
except:
data += hexlify(tmp)
print(data)
finally:
print("closing socket")
self.sock.close()