示例#1
0
 def __init__(self, host, portnumber, delay = 0, workers = 5, debug = 1):
     JsonRPCBase.__init__(self, workers = workers, debug = debug)
     self.host = host
     self.portnumber = portnumber
     self.delay = delay
     self.client = Graphline(
         TCPCLIENT = TCPClient(self.host, self.portnumber, self.delay),
         PROTOCOL = self.jsonprotocol(),
         linkages = { ('TCPCLIENT', 'outbox') : ('PROTOCOL', 'inbox'),
                      ('PROTOCOL', 'outbox') : ('TCPCLIENT', 'inbox'),                          
                      ('TCPCLIENT', 'signal') : ('PROTOCOL', 'control'),
                      ('PROTOCOL', 'signal') : ('TCPCLIENT', 'control'), 
                     } )
     self.handle = Handle(self.client)
示例#2
0
                item = self.recv('inbox')
                self.send(item[::-1], 'outbox')
            else:
                self.pause()
            yield 1


# If using zap=True, number of breaks is increased
# background(zap=True).start()
background(zap=True).start()

# Uncomment this -> ~40% fail, it doesn't seem matter how long we sleep
time.sleep(1)
# time.sleep(5)

reverser = Handle(Reverser()).activate()

# There seems that there is not a big difference uncommenting this
# time.sleep(1)

reverser.put("hello world", "inbox")

# There seems that there is not a big difference uncommenting this
# time.sleep(1)

n = 0
print '*' * 30
initial = time.time()

while True:
    try:
示例#3
0
 def setUp(self):
     #		print "begin setUp..."
     r = Reverser()
     h = Handle(r)
     self.reverser = h.activate()
示例#4
0
# -------------------------------------------------------------------------

# a slightly more complicated example of a TCP client, where we define an echo.

from Kamaelia.Chassis.ConnectedServer import SimpleServer
from Kamaelia.Protocol.EchoProtocol import EchoProtocol
from Kamaelia.Internet.TCPClient import TCPClient
from Axon.background import background
from Axon.Handle import Handle
import Queue
import time

background(slowmo=0.01).start()

PORT = 1900
# This starts an echo server in the background.
SimpleServer(protocol=EchoProtocol, port=PORT).activate()

# give the component time to commence listening on a port.
time.sleep(0.5)

echoClient = Handle(TCPClient(host="localhost", port=PORT)).activate()
while True:
    echoClient.put(raw_input(">>> "), "inbox")
    while 1:
        try:
            print echoClient.get("outbox")
            break
        except Queue.Empty:
            time.sleep(0.01)
示例#5
0
# limitations under the License.

from Axon.background import background
from Axon.Handle import Handle
from Kamaelia.Codec.Vorbis import VorbisDecode, AOAudioPlaybackAdaptor
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
from Kamaelia.Internet.TCPClient import TCPClient
import time
import Queue
import ao
background(slowmo=0.001).start()

filename = "./snail.ogg"

playStream = Handle(Pipeline(VorbisDecode(), AOAudioPlaybackAdaptor())).activate()
# set of components for playing the stream back.

host = "bbc.kamaelia.org"
port = 1500

client = Handle(TCPClient(host = host, port = port)).activate()
# component to grab a stream from the internet

filedump = open("streamdump.ogg", "w+b")

def get_item(handle):
    while 1:
        try:
            X = handle.get("outbox")
            return X
示例#6
0
    ##req = RequestOrNotification('long_calc', params = (100, 'progress_callback'), response_callback = ResponseCallback(callback_func = request_result))
    ##client.add_request_on_connect(req, wait=False)
    ##req = RequestOrNotification('double', params = (50,), response_callback = ResponseCallback(callback_func = request_result))
    ##client.add_request_on_connect(req, wait = True)
    ##req = RequestOrNotification('foo', params = {'callback': 'progress_callback' },  response_callback = ResponseCallback(callback_func = request_result))
    ##client.add_request_on_connect(req, wait = False)
    ##req = RequestOrNotification('bar', params = (3, ), response_callback = ResponseCallback(callback_func = request_result))
    ##client.add_request_on_connect(req)

    client.start()
    connection = None
    counter = 0
    while 1:
        counter += 1
        if len(client.jsonprotocol.connections) > 0 and not connection:
            print 'Got connection'
            connection = client.jsonprotocol.connections[0]
            repr(connection)
        sys.stdout.write('.' + str(counter))
        sys.stdout.flush()
        sleep(1)
        if counter == 2:
            print 'Sending request'
            req = RequestOrNotification('double',
                                        params=(3.142, ),
                                        response_callback=ResponseCallback(
                                            callback_func=request_result))
            h = Handle(connection)
            #h.activate()
            h.put(req, 'request')
示例#7
0
import time
from Axon.background import background
from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer
from Axon.Handle import Handle
background().start()

try:
    import Queue
    queue = Queue  # Python 3 compatibility change
except ImportError:
    # Python 3 compatibility change
    import queue
TD = Handle(
    TextDisplayer(position=(20, 90),
                  text_height=36,
                  screen_width=900,
                  screen_height=200,
                  background_color=(130, 0, 70),
                  text_color=(255, 255, 255))).activate()

TB = Handle(
    Textbox(position=(20, 340),
            text_height=36,
            screen_width=900,
            screen_height=400,
            background_color=(130, 0, 70),
            text_color=(255, 255, 255))).activate()

message = "hello\n"
while 1:
    time.sleep(1)
示例#8
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -------------------------------------------------------------------------

from Axon.background import background
from Axon.Handle import Handle
from Kamaelia.Codec.Vorbis import VorbisDecode, AOAudioPlaybackAdaptor
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
import time
import ao

background(slowmo=0.001).start()

filename = "../SupportingMediaFiles/KDE_Startup_2.ogg"

playStream = Handle(Pipeline(VorbisDecode(),
                             AOAudioPlaybackAdaptor())).activate()

# Play the ogg data in the background
oggdata = open(filename, "r+b").read()
playStream.put(oggdata, "inbox")
while True:
    time.sleep(0.1)
示例#9
0
            yield 1

        self.send(self.recv("control"), "signal")  # pass on the shutdown


from Kamaelia.Util.Backplane import *
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import *

# Test 1
if 0:
    # This works
    background().start()
    Backplane("TEST").activate()

    reverser = Handle(Pipeline(Reverser(), PublishTo("TEST"))).activate()

    Pipeline(SubscribeTo("TEST"), ConsoleEchoer()).activate()

    while True:
        line = sys.stdin.readline()
        if line == "":
            break
        line = line.rstrip()  # get rid of newline - looks odd otherwise :)

        reverser.put(line, "inbox")

# Test 2
if 0:
    # This works
    background().start()
示例#10
0
import Axon
from Axon.background import background
from Axon.Handle import Handle
from Kamaelia.UI.Pygame.Ticker import Ticker
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
import time

bg = background(slowmo=0.01).start()

ticker1 = Handle(Pipeline(
                            Ticker(background_colour=(128,48,128),
                                   render_left = 1,
                                   render_top = 1,
                                   render_right = 600,
                                   render_bottom = 200,
                                   position = (100, 250),
                            )
                   )
          ).activate()
ticker2 = Handle(Pipeline( 
                            Ticker(background_colour=(128,48,128),
                                render_left = 1,
                                render_top = 1,
                                render_right = 600,
                                render_bottom = 200,
                                position = (100, 0),
                            )
                   )
          ).activate()