urcontrol/tests/socketreceivetest.py

36 lines
752 B
Python
Raw Normal View History

2022-05-31 13:05:06 +00:00
import socket
import math
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host =""
port =30002
s.bind((host,port))
s.listen(1) # Number of connections
s.setblocking(False)
2022-05-31 13:26:53 +00:00
client = None
2022-05-31 13:05:06 +00:00
while True:
try:
client, address = s.accept()
print("Connected to", address)
except socket.error:
pass
2022-05-31 13:26:53 +00:00
if client is not None:
try:
data = client.recv( 1024 ).decode( 'utf-8' )
if data:
2022-05-31 13:34:27 +00:00
lastdata=data.split('\n')
splitdata=lastdata[-2].split(",")
print("lastdata="+str(lastdata))
2022-05-31 13:26:53 +00:00
2022-05-31 13:34:27 +00:00
#print("Received :", repr(data))
2022-05-31 13:26:53 +00:00
print(splitdata)
except socket.error:
pass
2022-05-31 13:05:06 +00:00
s.close()