Exemplo n.º 1
0
    def run(self, arg):
        print "Service base test:"
        # Create service: my_svc
        svc = Service("svcbase_test_svc")
        svc.codec = Service.CODEC_BINARY
        svc.start()

        # Listen
        ip = "127.0.0.1"
        port = 7788
        listen_sid = svc.listen(ip, port)
        print "Service {} listening in {}:{}, session Id: {}".format(svc.name, ip, port, listen_sid)

        # Connect to listen session.
        conn_sid = svc.connect(ip, port)
        print "Connect to {}:{} success, sid: {}".format(ip, port, conn_sid)

        # Send data.
        svc.send(conn_sid, TestData())
        # Test unhandled packet.
        svc.send(conn_sid, data=3, opcode=10086, status=0)

        # Create service: another_svc
        another = Service("another")
        another.codec = Service.CODEC_BINARY
        another.start()

        # Schedule.
        Service.schedule()

        # If deschedule, will gone to here.
        # Delete my_svc service.
        del Service.my_svc
        del Service.another
Exemplo n.º 2
0
    def run(self, arg):
        print 'Service base test:'
        # Create service: my_svc
        svc = Service('svcbase_test_svc')
        svc.codec = Service.CODEC_BINARY
        svc.start()

        # Listen
        ip = '127.0.0.1'
        port = 7788
        listen_sid = svc.listen(ip, port)
        print 'Service {} listening in {}:{}, session Id: {}'.format(svc.name, ip, port, listen_sid)

        # Connect to listen session.
        conn_sid = svc.connect(ip, port)
        print 'Connect to {}:{} success, sid: {}'.format(ip, port, conn_sid)

        # Send data.
        svc.send(conn_sid, TestData())
        # Test unhandled packet.
        svc.send(conn_sid, data=3, opcode=10086, status=0)

        # Create service: another_svc
        another = Service('another')
        another.codec = Service.CODEC_BINARY
        another.start()

        # Schedule.
        Service.schedule()

        # If deschedule, will gone to here.
        # Delete my_svc service.
        del Service.svcbase_test_svc
        del Service.another
Exemplo n.º 3
0
    def run(self, arg):
        print('Event test:')

        # Create service: event_test_svc
        svc = Service('event_test_svc')
        svc.codec = Service.CODEC_BINARY
        svc.start()
        svc.fps = 1

        Service.schedule()
Exemplo n.º 4
0
    def run(self, arg):
        print 'custom header parts test:'
        if not self._parse_args():
            return

        self._design_header()
        self._startup_svc()

        Service.schedule()

        print "press any key to exit..."
        raw_input()
Exemplo n.º 5
0
    def run(self, arg):
        print 'custom header parts test:'
        if not self._parse_args():
            return

        self._design_header()
        self._startup_svc()

        Service.schedule()

        print "press any key to exit..."
        raw_input()
Exemplo n.º 6
0
def main():
    client = Service(Service.CLIENT, 'client')
    client.codec = Service.CODEC_BINARY
    client.startasclient()

    server = Service(Service.SERVER, 'server')
    server.codec = Service.CODEC_BINARY
    server.startasserver('127.0.0.1', 7788)

    client2 = Service(Service.CLIENT, 'client2')
    client2.codec = Service.CODEC_BINARY
    client2.startasclient()

    Service.schedule()
Exemplo n.º 7
0
class MultiSvcTest(TestCase):
    def run(self, arg):
        print 'multi service test:'

        client = Service('multisvc_test_client')
        server = Service('multisvc_test_server')

        client.codec = Service.CODEC_JSON
        server.codec = Service.CODEC_JSON

        client.registercomp(ClientComp())
        server.registercomp(ServerComp())

        client.subscribe(TEST_RES, ClientPacketHandler())
        server.subscribe(TEST_REQ, ServerPacketHandler())

        #        client.presubscribe(TEST_RES, ClientPacketPreHandler())
        #        server.presubscribe(TEST_REQ, ServerPacketPreHandler())

        try:
            client.unify_presubscribe(ClientPacketUnifyPreHandler())
            server.unify_presubscribe(ServerPacketUnifyPreHandler())
        except llbc.error, e:
            print 'subscribe unify pre-handler to service failed'
            print 'reason: {}'.format(e)

        server.start()
        server.listen(TEST_IP, TEST_PORT)

        client.start()

        Service.schedule()
Exemplo n.º 8
0
    def run(self, *args, **kwargs):
        if len(_argv) < 4:
            print 'argument error, eg: python main.py server/client ip port [useBst = False]'
            return -1

        self._fetch_args()

        self._svc = Service('multicast_test_svc')

        svc = self._svc
        svc.registerfacade(_TestFacade(self._as_client, self._use_bst))

        if self._as_client:
            self._start_as_client()
        else:
            self._start_as_server()

        Service.schedule()