示例#1
0
def main():
    #This line is so that the HTTPRequestHandler knows what component to route requests to.
    routing = [ ['/', WSGIFactory(WsgiConfig, url_list)] ]
    server = ServerCore(protocol=HTTPProtocol(routing),
                        port=port,
                        socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1))
    print 'Serving on port %s' % (port)
    server.run()
示例#2
0
class JsonRpcTCPServer(JsonRPCBase):
    def __init__(self, portnumber, workers = 5, debug = 1):
        JsonRPCBase.__init__(self, workers = workers, debug = debug)
        self.portnumber = portnumber
        self.server = None
    def start(self):
        if self.debug: print ('Starting JSON-RPC server on port %s' % self.portnumber)
        self.server = ServerCore( protocol = self.jsonprotocol, port = self.portnumber )
        self.server.run()
示例#3
0
class JsonRpcTCPServer(JsonRPCBase):
    def __init__(self, portnumber, workers = 5, debug = 1):
        JsonRPCBase.__init__(self, workers = workers, debug = debug)
        self.portnumber = portnumber
        self.server = None
    def start(self):
        if self.debug: print 'Starting JSON-RPC server on port %s' % self.portnumber
        self.server = ServerCore( protocol = self.jsonprotocol, port = self.portnumber )
        self.server.run()
示例#4
0
        self.send(self.recv("control"), "signal")


from Kamaelia.Experimental.PythonInterpreter import InterpreterTransformer


def NetInterpreter(*args, **argv):
    return Pipeline(
        PureTransformer(lambda x: str(x).rstrip()),
        PureTransformer(lambda x: str(x).replace("\r", "")),
        InterpreterTransformer(),
        PureTransformer(lambda x: str(x) + "\r\n>>> "),
    )


ServerCore(protocol=NetInterpreter,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
           port=8765).activate()

Pipeline(
    PeriodicWakeup(interval=1),
    WakeableIntrospector(),
    PureTransformer(lambda x: str(len(x)) + " " + str(x) + "\n"),
    Uniq(),
    ConsoleEchoer(),
).activate()

ServerCore(protocol=Echo,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
           port=1234).run()
示例#5
0
        Pipeline(
            ConsoleReader(),
            InterpreterTransformer(),
            ConsoleEchoer(),
        ).run()


#FILE: Server Embeddable
    if 0:
        from Kamaelia.Chassis.ConnectedServer import ServerCore
        from Kamaelia.Util.PureTransformer import PureTransformer

        def NetInterpreter(*args, **argv):
            return Pipeline(
                        PureTransformer(lambda x: str(x).rstrip()),
                        InterpreterTransformer(),
                        PureTransformer(lambda x: str(x)+"\r\n>>> "),
                   )

        ServerCore(protocol=NetInterpreter, port=1236).run()


#FILE: Pygame Embeddable
    if 1:
        from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer
        Pipeline(
            Textbox(size = (800, 300), position = (100,380)),
            InterpreterTransformer(),
            TextDisplayer(size = (800, 300), position = (100,40)),
        ).run()
示例#6
0
else:
    Pipeline(
        SubscribeTo("OUIJAOUT"),
        TextDisplayer(position=(250,48),
                      size=(500,322),
                      text_height=25),
    ).activate()

def Publisher(*args, **argd):
    return PublishTo("OPENCV_VOTES")

# For receiving Voting information from Matt's Open CV system

ServerCore(protocol = Publisher, port=1500,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
           ).activate()

Pipeline(
    SubscribeTo("OPENCV_VOTES"),
    ConsoleEchoer(forwarder=True),
    OpenCVAnalyser(),
    ConsoleEchoer(forwarder=True),
    PublishTo("USERRESPONSE"),
#    PureTransformer(lambda x: repr(x)+"\n"),
).activate()

Pipeline(
    SubscribeTo("PINGERCONTROL"),
    Pinger(sleep=5),
    PublishTo("SCHEDULECONTROL"),
示例#7
0
 def start(self):
     if self.debug:
         print 'Starting JSON-RPC server on port %s' % self.portnumber
     self.server = ServerCore(protocol=self.jsonprotocol,
                              port=self.portnumber)
     self.server.run()
示例#8
0
                    self.doMessagesMenu(user)
        except GotShutdownMessage:
            self.send(self.recv("control"), "signal")
        yield 1


def CompositeBulletinBoardProtocol(**argd):
    ConnectionInfo = {}
    ConnectionInfo.update(argd)
    return Seq(
        Authenticator(State=ConnectionInfo),
        UserRetriever(State=ConnectionInfo),
        MessageBoardUI(State=ConnectionInfo),
        StateSaverLogout(State=ConnectionInfo),
    )


def readUsers():
    f = open("users.passwd")
    users = f.read()
    f.close()
    users = cjson.decode(users)
    return users


users = readUsers()

ServerCore(protocol=CompositeBulletinBoardProtocol,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
           port=1600).run()
示例#9
0
def run_program():
    """The main entry point for the application."""
    try:
        zip = zipfile.ZipFile(sys.argv[0], 'r')

        #prompt the user if this executable is corrupt
        corrupt = zip.testzip()
        if corrupt:
            Console.prompt_corrupt(corrupt)

        initializeLogger()
        home_path = os.environ['HOME']

        #prompt the user to install the necessary software if this is the first
        #time to run Kamaelia WebServe
        if not os.path.exists(home_path + '/kp.ini'):
            autoinstall(zip, home_path, 'Kamaelia WebServe')

        zip.close()

        #Extract data from Config Files and organize it into dictionaries
        configs = ParseConfigFile('~/kp.ini', DictFormatter())
        ServerConfig = configs['SERVER']
        WsgiConfig = configs['WSGI']
        StaticConfig = configs['STATIC']

        processPyPath(ServerConfig)
        normalizeWsgiVars(WsgiConfig)

        url_list = ParseUrlFile(WsgiConfig['url_list'])
        normalizeUrlList(url_list)

        StaticConfig['homedirectory'] = os.path.expanduser(
            StaticConfig['homedirectory'])
        log = os.path.expanduser(ServerConfig['log'])
        routing = [
            [
                StaticConfig['url'],
                MinimalFactory(StaticConfig['index'],
                               StaticConfig['homedirectory'])
            ],
            ["/", WSGIFactory(WsgiConfig, url_list, log)],
        ]

        kp = ServerCore(protocol=HTTPProtocol(routing),
                        port=int(ServerConfig['port']),
                        socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                                       1))

        info('Serving on port %s' % (ServerConfig['port']), _logger_suffix)
    except:
        import traceback
        print 'There was an error!  Info is in %s/error.log' % (os.getcwd())
        file = open('error.log', 'a')
        traceback.print_exc(file=file)
        file.write('\n')
        file.close()
        sys.exit(1)
    try:
        kp.run()
    except KeyboardInterrupt:
        print "Halting server!"
    except:
        #Something's gone horribly wrong and the program doesn't know what to do
        #about it.
        import traceback
        traceback.print_exc()
        print "===========FATAL ERROR==========="
    finally:
        kp.stop()
        logging.shutdown()
示例#10
0
            self.pause()
            yield 1

    def getMsg(self):
        if self.dataReady("control"):
            raise GotShutdownMessage()
        return self.recv("inbox")

    def main(self):
        try:
            while 1:
                self.send("login: "******"outbox")
                yield WaitComplete( self.waitMsg() )
                username = self.getMsg()

                self.send("password: "******"outbox")
                yield WaitComplete( self.waitMsg() )
                password= self.getMsg()

                print
                print repr(username), repr(password)
                self.pause()
                yield 1
        except GotShutdownMessage:
            self.send(self.recv("control"), "signal")
        self.send( Axon.Ipc.producerFinished(), "signal")

ServerCore(protocol=RequestResponseComponent,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
           port=1600).run()
示例#11
0
        # and shutdown nicely
        self.send(Axon.Ipc.producerFinished(self), "signal")
        yield 1


def EchoHandler(request):
    """\
    This handler will join the 'Cat' handler and ExampleWrapper together
    such that the 'Cat' will forward the request dictionary on to the
    ExampleWrapper, which will wrap the data in a response dictionary and
    forward the data on to the HTTP Server.
    """
    return Pipeline(Cat(request), ExampleWrapper())


def servePage(request):
    return Minimal(request=request,
                   homedirectory=homedirectory,
                   indexfilename=indexfilename)


routing = [
    ["/echo", EchoHandler],
    ["/hello", HelloHandler],
    ["/", MinimalFactory(indexfilename, homedirectory)],
]

ServerCore(protocol=HTTPProtocol(routing),
           port=8082,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)).run()
示例#12
0
        Pipeline(
            ConsoleReader(">> "),
            ArdBot(ser),
            ConsoleEchoer(),
        ).run()

    if 1:
        from Kamaelia.Util.Backplane import *
        Backplane("ARDBOT").activate()

        Pipeline(
            ConsoleReader(">> "),
            PublishTo("ARDBOT"),
        ).activate()

        Pipeline(
            SubscribeTo("ARDBOT"),
            ArdBot(ser),
            ConsoleEchoer(),
        ).activate()

        def LocalArdBot(*argv, **argd):
            return PublishTo("ARDBOT")

        import socket
        from Kamaelia.Chassis.ConnectedServer import ServerCore
        ServerCore(protocol=LocalArdBot,
                   port=1500,
                   socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                                  1)).run()
示例#13
0
    def main(self):
        self.send("no protocol attached\r\n\r\n")
        self.send(Axon.Ipc.producerFinished(), "signal")
        yield 1


class Authenticator(RequestResponseComponent):
    def main(self):
        try:
            while 1:
                self.send("login: "******"outbox")
                yield WaitComplete(self.waitMsg())
                username = self.getMsg()

                self.send("password: "******"outbox")
                yield WaitComplete(self.waitMsg())
                password = self.getMsg()

                print
                print repr(username), repr(password)
                self.pause()
                yield 1
        except GotShutdownMessage:
            self.send(self.recv("control"), "signal")
        self.send(Axon.Ipc.producerFinished(), "signal")


ServerCore(protocol=Authenticator,
           socketOptions=(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
           port=1600).run()
示例#14
0
 def start(self):
     if self.debug:
         print("Starting JSON-RPC server on port %s" % self.portnumber)
     self.server = ServerCore(protocol=self.jsonprotocol, port=self.portnumber)
     self.server.run()
示例#15
0
# (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.
import Axon
from Kamaelia.Chassis.ConnectedServer import ServerCore

class RequestResponseComponent(Axon.Component.component):
    def main(self):
        while not self.dataReady("control"):
            for msg in self.Inbox("inbox"):
                self.send(msg, "outbox")
            self.pause()
            yield 1
        self.send(self.recv("control"), "signal")

ServerCore(protocol=RequestResponseComponent,
           port=1599).run()

示例#16
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 Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Codec.Dirac import DiracDecoder
from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor
from Kamaelia.Util.RateFilter import MessageRateLimit
from Kamaelia.UI.Pygame.VideoSurface import VideoSurface
from Kamaelia.Chassis.ConnectedServer import ServerCore
from Kamaelia.Video.PixFormatConversion import ToRGB_interleaved

import sys
framerate = 10


def player(*argv, **argd):
    return Pipeline(
        DiracDecoder(),
        ToRGB_interleaved(),
        VideoSurface(),
    )


ServerCore(protocol=player, port=1500).run()