Ejemplo n.º 1
0
# 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.

# 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.likefile import LikeFile, schedulerThread
import time

schedulerThread(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 = LikeFile(TCPClient(host="localhost", port=PORT))
while True:
    echoClient.put(raw_input(">>> "))
    print echoClient.get()
Ejemplo n.º 2
0
from Axon.likefile import LikeFile, schedulerThread
import time, Axon
from Sprites.BasicSprite import BasicSprite
from Sprites.SpriteScheduler import SpriteScheduler
from Simplegame import *


class catMaker(Axon.Component.component):
    """discards input, makes one cat per item on inbox."""
    def main(self):
        self.spritescheduler = SpriteScheduler(cat_args, cat_sprites, background, screen_surface, MyGamesEvents).activate()
        yield 1 # to make sure spritescheduler's main gets called once - there's code outside the loop there that needs to run.
        while True:
            while self.dataReady("inbox"):
                discardedfornow = self.recv("inbox")
                cat_appear_wav.play()
                self.spritescheduler.allsprites.add(make_cat(*self.spritescheduler.cat_args))
            self.pause()
            yield 1

bg = schedulerThread(slowmo=0.01).start()
catmaker = LikeFile(catMaker())
catmaker.activate()

max_cats = 10
for i in xrange(0, max_cats):
    time.sleep(0.5)
    catmaker.put(i)
print "cats over!"
time.sleep(5)
Ejemplo n.º 3
0
# 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.

# An example of using likefile to pass audo data for on the fly compression.

import Axon.likefile, time
from Kamaelia.Audio.Codec.PyMedia.Encoder import Encoder
from Kamaelia.Internet.TCPClient import TCPClient
likefile.schedulerThread(slowmo=0.01).start()

infile = "./stereo.wav"
outfile = "./outfile.mp3"

enc = likefile.LikeFile(Encoder("mp3", bitrate=128000, sample_rate=44100, channels=2))

output = open(outfile, "w+b")

while True:
    data = output.read(1024)
    print "about to sleep"
    time.sleep(1)
    print "slept"
    enc.put(data)
    data = enc.get()
Ejemplo n.º 4
0
# 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.

# An example of using likefile to pass audo data for on the fly compression.

import Axon.likefile, time
from Kamaelia.Audio.Codec.PyMedia.Encoder import Encoder
from Kamaelia.Internet.TCPClient import TCPClient
likefile.schedulerThread(slowmo=0.01).start()

infile = "./stereo.wav"
outfile = "./outfile.mp3"

enc = likefile.LikeFile(
    Encoder("mp3", bitrate=128000, sample_rate=44100, channels=2))

output = open(outfile, "w+b")

while True:
    data = output.read(1024)
    print "about to sleep"
    time.sleep(1)
    print "slept"
    enc.put(data)
Ejemplo n.º 5
0
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1)
#
# (1) Kamaelia Contributors are listed in the AUTHORS file and at
#     http://www.kamaelia.org/AUTHORS - please extend this file,
#     not this notice.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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.likefile import LikeFile, schedulerThread
from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
background = schedulerThread().start()
p = LikeFile(SimpleHTTPClient())
p.put("http://google.com")
p.put("http://slashdot.org")
p.put("http://whatismyip.org")
google = p.get()
slashdot = p.get()
whatismyip = p.get()
p.shutdown()
print "google is", len(google), "bytes long, and slashdot is", len(slashdot), "bytes long. Also, our IP address is:", whatismyip
Ejemplo n.º 6
0
from Sprites.BasicSprite import BasicSprite
from Sprites.SpriteScheduler import SpriteScheduler
from Kamaelia.UI.Pygame.EventHandler import EventHandler
from Simplegame import *

from Kamaelia.Automata.Behaviours import (
    bouncingFloat,
    cartesianPingPong,
    loopingCounter,
    continuousIdentity,
    continuousZero,
    continuousOne,
)
from Kamaelia.Util.Fanout import Fanout

bg = schedulerThread().start()

global spritescheduler


class MyGamesEvents(EventHandler):
    def __init__(self, cat_args, trace=1):
        self.trace = 0
        self.cat_args = cat_args

    def keydown(self, unicode, key, mod, where):
        if key == 113:  # "Q"
            raise "QUIT"


class CatSprite(BasicSprite):
Ejemplo n.º 7
0
#
# Proper likefile control of a sprite handler
#

from Axon.likefile import LikeFile, schedulerThread
import time, Axon, os, random, pygame, math, threading
from Sprites.BasicSprite import BasicSprite
from Sprites.SpriteScheduler import SpriteScheduler
from Kamaelia.UI.Pygame.EventHandler import EventHandler
from Simplegame import *

from Kamaelia.Automata.Behaviours import bouncingFloat, cartesianPingPong, loopingCounter, continuousIdentity, continuousZero, continuousOne
from Kamaelia.Util.Fanout import Fanout

bg = schedulerThread().start()

global spritescheduler


class MyGamesEvents(EventHandler):
    def __init__(self, cat_args, trace=1, ):
        self.trace = 0
        self.cat_args = cat_args
    def keydown(self, unicode, key, mod, where):
        if key == 113: # "Q"
            raise "QUIT"

class CatSprite(BasicSprite):
    def main(self):
        spritescheduler.allsprites.add(self)
Ejemplo n.º 8
0
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1)
#
# (1) Kamaelia Contributors are listed in the AUTHORS file and at
#     http://www.kamaelia.org/AUTHORS - please extend this file,
#     not this notice.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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.likefile import LikeFile, schedulerThread
from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
background = schedulerThread().start()
p = LikeFile(SimpleHTTPClient())
p.put("http://google.com")
p.put("http://slashdot.org")
p.put("http://whatismyip.org")
google = p.get()
slashdot = p.get()
whatismyip = p.get()
p.shutdown()
print "google is", len(google), "bytes long, and slashdot is", len(
    slashdot), "bytes long. Also, our IP address is:", whatismyip
Ejemplo n.º 9
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.

# This is a quick example of using kamaelia as a general tcp client in your system.

host = "irc.freenode.net"
port = 6667

import Axon.likefile, time
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Internet.TCPClient import TCPClient

likefile.schedulerThread().start()

print "what channel on freenode?"
channel = raw_input(
    ">>> ")  # this is to prevent spammage of the default settings.

client = likefile.LikeFile(TCPClient(host=host, port=port))
time.sleep(1)
client.put("user likefile likefile likefile :likefile\n")
client.put("nick likefile\n")
client.put("JOIN %s\n" % channel)
while True:
    print client.get()
Ejemplo n.º 10
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.

# This is a quick example of using kamaelia as a general tcp client in your system.


host = "irc.freenode.net"
port = 6667

import Axon.likefile, time
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Internet.TCPClient import TCPClient
likefile.schedulerThread().start()

print "what channel on freenode?"
channel = raw_input(">>> ") # this is to prevent spammage of the default settings.

client = likefile.LikeFile(TCPClient(host = host, port = port))
time.sleep(1)
client.put("user likefile likefile likefile :likefile\n")
client.put("nick likefile\n")
client.put("JOIN %s\n" % channel)
while True:
    print client.get()