urcontrol/tests/socketreceivetest.py
2022-05-31 15:34:27 +02:00

36 lines
No EOL
752 B
Python

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)
client = None
while True:
try:
client, address = s.accept()
print("Connected to", address)
except socket.error:
pass
if client is not None:
try:
data = client.recv( 1024 ).decode( 'utf-8' )
if data:
lastdata=data.split('\n')
splitdata=lastdata[-2].split(",")
print("lastdata="+str(lastdata))
#print("Received :", repr(data))
print(splitdata)
except socket.error:
pass
s.close()