LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-08-2009, 01:54 PM   #1
hoes
Member
 
Registered: Sep 2005
Distribution: debian, linux from scratch
Posts: 89

Rep: Reputation: 20
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:
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
 
  


Reply


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 07:43 PM
passing a structure from client to server cynthia_thomas Programming 3 02-28-2006 06:57 AM
python exception like structure with a timer shanenin Programming 4 08-20-2005 10:44 AM
How to set up an thin client server? franksun Linux - Enterprise 1 02-06-2005 12:07 AM
about client server structure on Linux 7.1 pravintakpire Linux - Newbie 3 12-05-2001 03:52 PM


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

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