fireandforget version

This commit is contained in:
Sam 2020-10-10 19:29:07 +02:00
parent 4faf53168d
commit 93cbcfefd5
24 changed files with 565 additions and 1840 deletions

BIN
Pd/.DS_Store vendored Normal file

Binary file not shown.

23
Pd/LJsender.pd Normal file
View file

@ -0,0 +1,23 @@
#N canvas 468 143 709 527 10;
#X msg 60 237 disconnect;
#X floatatom 27 294 0 0 0 0 - - -;
#X text 22 315 Outlet is nonzero if connection is open \, zero otherwise.
;
#X msg 37 60 send mytext trololo;
#X obj 28 267 netsend 1;
#X msg 51 125 send /pl/0/0 (150 2300 65280) (170 170 65280) (230 170
65280) (210 230 65280) (150 230 65280);
#X text 258 29 LJ Sender;
#X msg 46 84 send /pl/0/0 150 2300 65280 170 170 65280 230 170 65280
210 230 65280 150 230 65280;
#X msg 26 39 connect 127.0.0.1 8083;
#X msg 58 165 send /pl/0/0 [(150.0:230.0:65280) (170.0:170.0:65280)
(230.0:170.0:65280) (210.0:230.0:65280) (150.0:230.0:65280)];
#X text 444 174 <- le mieux;
#X connect 0 0 4 0;
#X connect 3 0 4 0;
#X connect 4 0 1 0;
#X connect 5 0 4 0;
#X connect 7 0 4 0;
#X connect 8 0 4 0;
#X connect 9 0 4 0;

106
Pd/ljpd.py Normal file
View file

@ -0,0 +1,106 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
LJPD
Udp server to redis
v0.1b
'''
import traceback, time
import argparse
import socket
import _thread
import redis
print()
print ("LJPD")
print ("Arguments parsing if needed...")
argsparser = argparse.ArgumentParser(description="dumpUDP v0.1b help mode")
argsparser.add_argument("-i","--IP",help="IP to bind to (0.0.0.0 by default)", type=str)
argsparser.add_argument("-p","--port",help="UDP port to bind to (9000 by default)", type=str)
argsparser.add_argument("-l","--lj",help="LJ IP address (127.0.0.1 by default)", type=str)
args = argsparser.parse_args()
# LJ server IP name
if args.IP:
ljIP = lj.IP
else:
ljIP = "127.0.0.1"
# Server
if args.IP:
serverIP = args.IP
else:
serverIP = "0.0.0.0"
# ORCA destination device
if args.port:
UDPORT = int(args.port)
else:
UDPORT = 8083
print("Connecting to Redis...")
r = redis.StrictRedis(host= ljIP, port=6379, db=0)
def GetTime():
return time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
def udp_thread():
while True:
payload, client_address = sock.recvfrom(1024)
udpath = payload.decode('utf_8')
print(GetTime(),"From", str(client_address),"got", udpath )
#r.set('/pl/0/0', "/pl/"+str(clientnumber)+"/")
#print(udpath[0:1], " ",udpath[1:2], " ",udpath[2:3], " ",udpath[3:4], " " )
# Reply to client
bytesToSend = str.encode("ACK :"+str(payload))
serverAddressPort = (client_address, UDPORT)
bufferSize = 1024
#sock.sendto(bytesToSend, serverAddressPort)
sock.sendto(bytesToSend, client_address)
time.sleep(0.005)
def Start(serverIP, UDPORT):
global sock
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server = ( serverIP,UDPORT)
sock.bind(server)
_thread.start_new_thread(udp_thread, ())
# Launch server in another thread.
print("Launching UDP Server", serverIP,':', UDPORT)
Start(serverIP, UDPORT)
# Do something else
try:
while True:
time.sleep(0.005)
except Exception:
traceback.print_exc()
finally:
print("")
print("ljpd stopped.")