Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-08-2009, 02:54 PM   #1
Registered: Sep 2005
Distribution: debian, linux from scratch
Posts: 122

Rep: Reputation: 27
Ices0 and python: trying to set up server/client structure

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:
# A thread which listens to the socket
class sockserver(threading.Thread):
	def __init__(self):
	def run(self):
		global UPDSock
		host = 'localhost'
		port = 4444 
		buf = 1024
		addr = (host,port)
		UDPSock = socket(AF_INET,SOCK_DGRAM) 
		while 1:
			data = UDPSock.recv(buf)
			if not data:
				print('Client quit')

# 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()
	if os.path.isdir(basedir + genre):
		searchdir = basedir + genre
		searchdir = basedir		
	songbuf = []
	for i in ext:
		cmd = 'find "' + searchdir + '" -iname "' + i + '"' 
		tempbuf = os.popen(cmd).readlines()
	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:
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.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
zeroconf (python): client doesn't get to see the server eantoranz Programming 0 04-13-2009 08:43 PM
passing a structure from client to server cynthia_thomas Programming 3 02-28-2006 07:57 AM
python exception like structure with a timer shanenin Programming 4 08-20-2005 11:44 AM
How to set up an thin client server? franksun Linux - Enterprise 1 02-06-2005 01:07 AM
about client server structure on Linux 7.1 pravintakpire Linux - Newbie 3 12-05-2001 04:52 PM

All times are GMT -5. The time now is 12:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration