Ejemplo n.º 1
0
    def connectionMade(self):
        moveCommandHandler = CLIShell.CommandHandler(
            "move",
            "Tell the bot to move (1=North, 2=South, 3=East, 4=West)",
            mode=CLIShell.CommandHandler.SINGLETON_MODE,
            defaultCb=self.__sendBotMove)
        lookCommandHandler = CLIShell.CommandHandler("look",
                                                     "Tell the Bot to scan",
                                                     self.__sendBotLook)
        workCommandHandler = CLIShell.CommandHandler("work",
                                                     "Tell the Bot to work",
                                                     self.__sendBotWork)
        inventoryCommandHandler = CLIShell.CommandHandler(
            "inventory", "Get the bot's inventory", self.__sendBotInventory)
        unloadCommandHandler = CLIShell.CommandHandler(
            "unload", "Tell the Bot to unload inventory", self.__sendBotUnload)
        locationCommandHandler = CLIShell.CommandHandler(
            "location", "Get the bot's location", self.__sendBotLocation)

        self.registerCommand(moveCommandHandler)
        self.registerCommand(lookCommandHandler)
        self.registerCommand(workCommandHandler)
        self.registerCommand(unloadCommandHandler)
        self.registerCommand(locationCommandHandler)
        self.registerCommand(inventoryCommandHandler)

        networkSettings = PlaygroundNetworkSettings()
        networkSettings.configureNetworkStackFromPath("./ProtocolStack")
        playgroundEndpoint = GateServerEndpoint(reactor, 10001,
                                                networkSettings)
        playgroundEndpoint.listen(self)

        self.deferToResponse = Deferred()
                fname = parsedFirstLine[1]
                if os.path.isfile(fname):
                    with open(fname, 'r') as fin:
                        self.transport.write("%s 200 OK\r\n Content-Type: text/plain\r\n Content-length: %i\r\n\r\n%s" % (
                            parsedFirstLine[2], len(request), fin.read()))
                else:
                    with open("404.html", 'r') as fin:
                        self.transport.write("%s 404 Not Found\r\n Content-Type: text/plain\r\n Content-length: %i\r\n\r\n%s" % (
                            parsedFirstLine[2], len(request), fin.read()))

            else:
                with open("BadRequest.html", 'r') as fin:
                    self.transport.write("%s 400 Bad Request\r\n Content-Type: text/plain\r\n Content-length: %i\r\n\r\n%s" % (
                        parsedFirstLine[2], len(request), fin.read()))

        else:
            with open("BadRequest.html", 'r') as fin:
                self.transport.write("%s 400 Bad Request\r\n Content-Type: text/plain\r\n Content-length: %i\r\n\r\n%s" % (
                    parsedFirstLine[2], len(request), fin.read()))

        os.chdir('..')
        self.transport.loseConnection()

class HttpFactory(Factory):
    protocol = HttpResponse

endpoint = GateServerEndpoint.CreateFromConfig(reactor, 101)
endpoint.listen(HttpFactory())
reactor.run()

    # Set up the client base
    #client = ClientBase(myAddress)
    #serverAddress, serverPortString = sys.argv[1:3]
    #chaperonePort = 9090#int(serverPortString)

    if mode.lower() == "server":
        # This guy will be the server. Create an instance of the factory
        echoProtocolServer = EchoServer()

        # install the echoProtocolServer (factory) on playground port 101
        #client.listen(echoProtocolServer, 101, connectionType=connectionType)

        # tell the playground client to connect to playground server and start running
        #client.connectToChaperone(chaperoneAddr, chaperonePort)
        echoServerEndpoint = GateServerEndpoint.CreateFromConfig(
            reactor, 13370, gateKey, networkStack=RIPProtocol)
        d = echoServerEndpoint.listen(echoProtocolServer)
        d.addErrback(logger.error)

    else:
        echoServerAddr = mode
        #try:
        #    echoServerAddr = PlaygroundAddress.FromString(mode)
        #except:
        #    sys.exit(USAGE)
        # This guy will be the client. The server's address is hard coded
        echoClientEndpoint = GateClientEndpoint.CreateFromConfig(
            reactor, echoServerAddr, 13370, gateKey, networkStack=RIPProtocol)
        tester = ClientTest(echoServerAddr, echoClientEndpoint)

        stdio.StandardIO(tester)
Ejemplo n.º 4
0
    # Set up the client base
    #client = ClientBase(myAddress)
    #serverAddress, serverPortString = sys.argv[1:3]
    #chaperonePort = 9090#int(serverPortString)

    if mode.lower() == "server":
        # This guy will be the server. Create an instance of the factory
        echoProtocolServer = EchoServer()

        # install the echoProtocolServer (factory) on playground port 101
        #client.listen(echoProtocolServer, 101, connectionType=connectionType)

        # tell the playground client to connect to playground server and start running
        #client.connectToChaperone(chaperoneAddr, chaperonePort)
        echoServerEndpoint = GateServerEndpoint.CreateFromConfig(
            reactor, 101, gateKey, networkStack=SampleStack)
        d = echoServerEndpoint.listen(echoProtocolServer)
        d.addErrback(logger.error)

    else:
        echoServerAddr = mode
        #try:
        #    echoServerAddr = PlaygroundAddress.FromString(mode)
        #except:
        #    sys.exit(USAGE)
        # This guy will be the client. The server's address is hard coded
        echoClientEndpoint = GateClientEndpoint.CreateFromConfig(
            reactor, echoServerAddr, 101, gateKey, networkStack=SampleStack)
        tester = ClientTest(echoServerAddr, echoClientEndpoint)

        stdio.StandardIO(tester)
Ejemplo n.º 5
0
def main():
    #endpoint = GateServerEndpoint.CreateFromConfig(reactor, 101, "gatekey1", networkStack=KissProtocol)
    endpoint = GateServerEndpoint.CreateFromConfig(reactor, 101, "gatekey1", networkStack=RipStack)
    endpoint.listen(EchoFactory())
    reactor.run()
Ejemplo n.º 6
0
    # Set up the client base
    #client = ClientBase(myAddress)
    #serverAddress, serverPortString = sys.argv[1:3]
    #chaperonePort = 9090#int(serverPortString)

    if mode.lower() == "server":
        # This guy will be the server. Create an instance of the factory
        echoProtocolServer = EchoServer()

        # install the echoProtocolServer (factory) on playground port 101
        #client.listen(echoProtocolServer, 101, connectionType=connectionType)

        # tell the playground client to connect to playground server and start running
        #client.connectToChaperone(chaperoneAddr, chaperonePort)
        echoServerEndpoint = GateServerEndpoint.CreateFromConfig(
            reactor, 101, gateKey, networkStack=RipStackAuthentication)
        d = echoServerEndpoint.listen(echoProtocolServer)
        d.addErrback(logger.error)

    else:
        echoServerAddr = mode
        #try:
        #    echoServerAddr = PlaygroundAddress.FromString(mode)
        #except:
        #    sys.exit(USAGE)
        # This guy will be the client. The server's address is hard coded
        echoClientEndpoint = GateClientEndpoint.CreateFromConfig(
            reactor,
            echoServerAddr,
            101,
            gateKey,
def connectEndpointToGate(port, g2gconn, stack, hpFactory, logerror):
    hpServerEndpoint = GateServerEndpoint(reactor, port, "127.0.0.1",
                                          g2gconn.gatePort, stack)
    d = hpServerEndpoint.listen(hpFactory)
    d.addErrback(logerror)
    # Set up the client base
    #client = ClientBase(myAddress)
    #serverAddress, serverPortString = sys.argv[1:3]
    #chaperonePort = 9090#int(serverPortString)

    if mode.lower() == "server":
        # This guy will be the server. Create an instance of the factory
        echoProtocolServer = EchoServer()

        # install the echoProtocolServer (factory) on playground port 101
        #client.listen(echoProtocolServer, 101, connectionType=connectionType)

        # tell the playground client to connect to playground server and start running
        #client.connectToChaperone(chaperoneAddr, chaperonePort)
        echoServerEndpoint = GateServerEndpoint.CreateFromConfig(
            reactor, portNum, gateKey, networkStack=networkStack)
        d = echoServerEndpoint.listen(echoProtocolServer)
        d.addErrback(logger.error)

    else:
        echoServerAddr = mode
        #try:
        #    echoServerAddr = PlaygroundAddress.FromString(mode)
        #except:
        #    sys.exit(USAGE)
        # This guy will be the client. The server's address is hard coded
        echoClientEndpoint = GateClientEndpoint.CreateFromConfig(
            reactor,
            echoServerAddr,
            portNum,
            gateKey,