Esempio n. 1
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)

Esempio n. 2
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     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)
Esempio n. 3
0
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
        except Queue.Empty:
            time.sleep(0.001)

# Play the ogg data in the background
while True:
    data = get_item(client)
    filedump.write(data)
    # log the stream to disk
    playStream.put(data,"inbox")
    # and play it.

# this could all be done entirely within kamaelia but using likefile
# makes it easier to hook in external programs.
Esempio n. 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)
Esempio n. 5
0
    
    # requests on connect
    ##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')

Esempio n. 6
0
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()
    Backplane("TEST").activate()

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

    collector = Handle(SubscribeTo("TEST")).activate()

    while True:
        line = sys.stdin.readline()
        if line == "":
            break
Esempio n. 7
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')
Esempio n. 8
0

class Reverser(Axon.Component.component):
    def main(self):
        while True:
            if self.dataReady('inbox'):
                item = self.recv('inbox')
                self.send(item[::-1], 'outbox') # strings have no "reverse" method, hence this indexing 'hack'.
            else: self.pause()
            yield 1


sys.stderr.write("""_Similar_ to Unix's "rev" tool, implemented using likefile., type stuff, it reverses it\n""")

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

while True:
    line = sys.stdin.readline()
    if line == "":
       break
    line = line.rstrip() # get rid of the newline (Doesn't just strip newline, so rev(rev()) would not work 'correctly')
    reverser.put(line, "inbox")

    while 1:
        try:
            enil = reverser.get("outbox")
            break
        except queue.Empty:
            time.sleep(0.1)
            
    print (enil) # This is doesn't necessarily put the right whitespace back
Esempio n. 9
0
    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)
    try:
        data = TB.get("outbox")
        print(data)
        message = data
    except queue.Empty:
        pass
    TD.put(message, "inbox")
Esempio n. 10
0
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()
    Backplane("TEST").activate()

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

    collector = Handle(SubscribeTo("TEST")).activate()

    while True:
        line = sys.stdin.readline()
        if line == "":
            break
Esempio n. 11
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)
Esempio n. 12
0
                   )
          ).activate()

ticker3 = Handle(Pipeline( 
                            Ticker(background_colour=(128,48,128),
                                render_left = 1,
                                render_top = 1,
                                render_right = 600,
                                render_bottom = 200,
                                position = (100, 500),
                            )
                   )
          ).activate()

for line in file("Ulysses", 'r+b'):
    line = line.rstrip() # kill the newlines - printing them in reverse order messes with the ticker.
    ticker1.put(line[::-1], "inbox")
    ticker2.put(line, "inbox")

time.sleep(5)

for line in file("Ulysses", 'r+b'):
    ticker3.put(line, "inbox")

time.sleep(10)

# we'll unceremoniously die now, since the ticker has no way to indicate when it's done drawing, or indeed to cleanly remove it from the pygame window. Sending
# a producerfinished would end it, but it'd remain in pygame.


Esempio n. 13
0
    )
).activate()

ticker3 = Handle(
    Pipeline(
        Ticker(
            background_colour=(128, 48, 128),
            render_left=1,
            render_top=1,
            render_right=600,
            render_bottom=200,
            position=(100, 500),
        )
    )
).activate()

for line in file("Ulysses", "r+b"):
    line = line.rstrip()  # kill the newlines - printing them in reverse order messes with the ticker.
    ticker1.put(line[::-1], "inbox")
    ticker2.put(line, "inbox")

time.sleep(5)

for line in file("Ulysses", "r+b"):
    ticker3.put(line, "inbox")

time.sleep(10)

# we'll unceremoniously die now, since the ticker has no way to indicate when it's done drawing, or indeed to cleanly remove it from the pygame window. Sending
# a producerfinished would end it, but it'd remain in pygame.
Esempio n. 14
0
                item = self.recv('inbox')
                self.send(
                    item[::-1], 'outbox'
                )  # strings have no "reverse" method, hence this indexing 'hack'.
            else:
                self.pause()
            yield 1


sys.stderr.write(
    """_Similar_ to Unix's "rev" tool, implemented using likefile., type stuff, it reverses it\n"""
)

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

while True:
    line = sys.stdin.readline()
    if line == "":
        break
    line = line.rstrip(
    )  # get rid of the newline (Doesn't just strip newline, so rev(rev()) would not work 'correctly')
    reverser.put(line, "inbox")

    while 1:
        try:
            enil = reverser.get("outbox")
            break
        except queue.Empty:
            time.sleep(0.1)

    print(enil)  # This is doesn't necessarily put the right whitespace back
Esempio n. 15
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.Protocol.HTTP.HTTPClient import SimpleHTTPClient
background = background().start()
import time
import Queue

p = Handle(SimpleHTTPClient()).activate()
p.put("http://google.com","inbox")
p.put("http://slashdot.org","inbox")
p.put("http://whatismyip.org","inbox")

def get_item(handle):
   while 1:
      try:
          item = handle.get("outbox")
          break
      except Queue.Empty:
          time.sleep(0.05)
   return item

google = get_item(p)
slashdot = get_item(p)
whatismyip = get_item(p)
Esempio n. 16
0
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)
    try:
       data = TB.get("outbox")
       print (data)
       message = data
    except queue.Empty:
       pass
    TD.put(message, "inbox")
Esempio n. 17
0

# 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:
        info = reverser.get("outbox")
    except:
        n += 1
        if n % 1000 == 0:
            current = time.time()
Esempio n. 18
0
            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:
        info = reverser.get("outbox")
    except:
        n += 1
        if n % 1000 == 0:
            current = time.time()