Hi people,
I installed icecast2.3.2 and ices 0.4.
I have set up a python script (python-2.5.2) to send songs to ices.
I noticed that the script keeps running in some way, because I can store a tuple containing all the songs I would like to play.
I want to be able to determine the next song that is played.
Because the script keeps running I tried implementing a server/client architecture.
The script would be the server listening to a socket at the localhost.
This works but not completely.
I would like the messages to arrive instantly.
They wait with arriving until three songs are requested from the script.
So chronologically this looks like:
[ A song is playing ]
[ Send messages using python]
[ A new song is obtained from the script]
[ Another new song is obtained]
[ A third song is obtained and the script notices the messages]
I was thinking that this could be the result of the script going to sleep and thus not listening to the socket. However if I sent multiple messages the all arrive at the same time with the same delay. It also doesn't matter whether the songs are played completely or if I use SIGUSR1 to get a new number.
This is part of my script:
Code:
# A thread which listens to the socket
class sockserver(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global UPDSock
host = 'localhost'
port = 4444
buf = 1024
addr = (host,port)
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
while 1:
data = UDPSock.recv(buf)
if not data:
print('Client quit')
else:
print(data)
# Function called to initialize your python environment.
# Should return 1 if ok, and 0 if something went wrong.
def ices_init ():
global songbuf
global buflen
background = sockserver()
background.start()
if os.path.isdir(basedir + genre):
searchdir = basedir + genre
else:
searchdir = basedir
songbuf = []
for i in ext:
cmd = 'find "' + searchdir + '" -iname "' + i + '"'
tempbuf = os.popen(cmd).readlines()
songbuf.extend(tempbuf)
random.shuffle(songbuf)
buflen = len(songbuf)
print 'Executing initialize() function..'
return 1
The rest of the code does not refer to the background thread and therefore I did not include it.
I use these commands from python to send the data:
Code:
host = 'localhost'
port = 4444
addr = (host,port)
sock = socket(AF_INET,SOCK_DGRAM)
sock.sendto(' testdata',addr)
I have also checked using one python instance as the server which would run:
UDPSock = socket(AF_INET,SOCK_DGRAM) when I wanted.
When I used another python instance to send the message I did have an instant arrival.
Has anyone got an idea what is happening and how I can assure instant arrival?
Also I'm quite new to python so If anyone has a better idea to communicate with an alive python script, that is also very welcome.
Hugo