File: shout_server.py

package info (click to toggle)
pyro 1%3A3.14-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,048 kB
  • ctags: 1,988
  • sloc: python: 11,194; xml: 128; sh: 52; makefile: 28
file content (36 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import sys, os
sys.path.insert(0,os.pardir)	# to find testserver.py

import testserver

import Pyro.core, Pyro.util

######## object that does the callbacks

class CallbackThing(Pyro.core.ObjBase):
	def __init__(self):
		Pyro.core.ObjBase.__init__(self)
		self.clients=[]
	def register(self, client):
		print 'REGISTER',client
		self.clients.append(client)
		#client._setOneway('callback') # don't wait for results for this method
	def shout(self, message):	
		print 'Got shout:',message
		# let it know to all clients!
		for c in self.clients[:]:		# use a copy of the list
			try:
				c.callback('Somebody shouted: '+message) # oneway call
			except Pyro.errors.ConnectionClosedError,x:
				# connection dropped, remove the listener if it's still there
				# check for existence because other thread may have killed it already
				if c in self.clients:
					self.clients.remove(c)
					print 'Removed dead listener',c


######## main program

testserver.start(CallbackThing,'callback')