Example #1
0
 def onupdate(self, ev):
     # print 'service update: {}'.format(d)
     self._call_times += 1
     if self._call_times == 100000:
         print 'Service update {} times, deschedule it'.format(
             self._call_times)
         Service.deschedule()
    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()
    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()
Example #4
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()
Example #5
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()
Example #6
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()
    def _startup_svc(self):
        # Create service
        svc = Service('customheaderparts_test_svc',
                      Service.RAW if self._is_raw else Service.NORMAL)

        # Create facade
        facade = _Facade(self._as_client, self._test_type)
        svc.registerfacade(facade)

        svc_type_repr = 'RAW' if self._is_raw else 'NORMAL'
        if self._as_client:
            while True:
                try:
                    session_id = svc.connect(self._ip, self._port)
                except (Exception, ), e:
                    print 'Connect to {}:{} failed, will continue to try...'.format(self._ip, self._port)
                else:
                    print 'Service[{}] connected to {}:{}, session_id: {}' \
                        .format(svc_type_repr, self._ip, self._port, session_id)
                    break
    def _startup_svc(self):
        # Create service
        svc = Service('customheaderparts_test_svc',
                      Service.RAW if self._is_raw else Service.NORMAL)

        # Create facade
        facade = _Facade(self._as_client, self._test_type)
        svc.registerfacade(facade)

        svc_type_repr = 'RAW' if self._is_raw else 'NORMAL'
        if self._as_client:
            while True:
                try:
                    session_id = svc.connect(self._ip, self._port)
                except (Exception, ), e:
                    print 'Connect to {}:{} failed, will continue to try...'.format(
                        self._ip, self._port)
                else:
                    print 'Service[{}] connected to {}:{}, session_id: {}' \
                        .format(svc_type_repr, self._ip, self._port, session_id)
                    break
Example #9
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
Example #10
0
 def onupdate(self, ev):
     # print 'service update: {}'.format(d)
     self._call_times += 1
     if self._call_times == 1000:
         print "Service update {} times, deschedule it".format(self._call_times)
         Service.deschedule()
    def _design_header(self):
        header_desc = PacketHeaderDesc()

        # part 0: length part
        len_part = PacketHeaderPartDesc()
        len_part.serial_no = 0
        len_part.part_len = 4
        len_part.is_len_part = True
        header_desc.add_part(len_part)

        # part 1: opcode part
        opcode_part = PacketHeaderPartDesc()
        opcode_part.serial_no = 1
        opcode_part.part_len = 2
        opcode_part.is_opcode_part = True
        opcode_part.is_len_included_self = False
        header_desc.add_part(opcode_part)

        # part 2: 4 bytes part, use to store sint32 value.
        sint32_part = PacketHeaderPartDesc()
        sint32_part.serial_no = 2
        sint32_part.part_len = 4
        sint32_part.is_len_included_self = False
        header_desc.add_part(sint32_part)

        # part 3: 8 bytes part, use to store sint64 value.
        sint64_part = PacketHeaderPartDesc()
        sint64_part.serial_no = 3
        sint64_part.part_len = 8
        header_desc.add_part(sint64_part)

        # part 4: 4 bytes part, use to store float4 value.
        float4_part = PacketHeaderPartDesc()
        float4_part.serial_no = 4
        float4_part.part_len = 4
        header_desc.add_part(float4_part)

        # part 5: 8 bytes part, use to store float8 value.
        float8_part = PacketHeaderPartDesc()
        float8_part.serial_no = 5
        float8_part.part_len = 8
        header_desc.add_part(float8_part)

        # part 6: 4 bytes part, use to store string: 'llbc'.
        llbcstr_part = PacketHeaderPartDesc()
        llbcstr_part.serial_no = 6
        llbcstr_part.part_len = 4
        llbcstr_part.is_len_included_self = False
        header_desc.add_part(llbcstr_part)

        # part 7: 13 bytes part, use to store string: 'hello python!'
        stdstr_part = PacketHeaderPartDesc()
        stdstr_part.serial_no = 7
        stdstr_part.part_len = 13
        header_desc.add_part(stdstr_part)

        # part 8: 20 bytes part, use to store string: 'hello bytearray!'
        bytearray_part = PacketHeaderPartDesc()
        bytearray_part.serial_no = 8
        bytearray_part.part_len = 20
        header_desc.add_part(bytearray_part)

        Service.set_header_desc(header_desc)
Example #12
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
Example #13
0
    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.registerfacade(ClientFacade())
        server.registerfacade(ServerFacade())

        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)
    def _design_header(self):
        header_desc = PacketHeaderDesc()

        # part 0: length part
        len_part = PacketHeaderPartDesc()
        len_part.serial_no = 0
        len_part.part_len = 4
        len_part.is_len_part = True
        header_desc.add_part(len_part)

        # part 1: opcode part
        opcode_part = PacketHeaderPartDesc()
        opcode_part.serial_no = 1
        opcode_part.part_len = 2
        opcode_part.is_opcode_part = True
        opcode_part.is_len_included_self = False
        header_desc.add_part(opcode_part)

        # part 2: 4 bytes part, use to store sint32 value.
        sint32_part = PacketHeaderPartDesc()
        sint32_part.serial_no = 2
        sint32_part.part_len = 4
        sint32_part.is_len_included_self = False
        header_desc.add_part(sint32_part)

        # part 3: 8 bytes part, use to store sint64 value.
        sint64_part = PacketHeaderPartDesc()
        sint64_part.serial_no = 3
        sint64_part.part_len = 8
        header_desc.add_part(sint64_part)

        # part 4: 4 bytes part, use to store float4 value.
        float4_part = PacketHeaderPartDesc()
        float4_part.serial_no = 4
        float4_part.part_len = 4
        header_desc.add_part(float4_part)

        # part 5: 8 bytes part, use to store float8 value.
        float8_part = PacketHeaderPartDesc()
        float8_part.serial_no = 5
        float8_part.part_len = 8
        header_desc.add_part(float8_part)

        # part 6: 4 bytes part, use to store string: 'llbc'.
        llbcstr_part = PacketHeaderPartDesc()
        llbcstr_part.serial_no = 6
        llbcstr_part.part_len = 4
        llbcstr_part.is_len_included_self = False
        header_desc.add_part(llbcstr_part)

        # part 7: 13 bytes part, use to store string: 'hello python!'
        stdstr_part = PacketHeaderPartDesc()
        stdstr_part.serial_no = 7
        stdstr_part.part_len = 13
        header_desc.add_part(stdstr_part)

        # part 8: 20 bytes part, use to store string: 'hello bytearray!'
        bytearray_part = PacketHeaderPartDesc()
        bytearray_part.serial_no = 8
        bytearray_part.part_len = 20
        header_desc.add_part(bytearray_part)

        Service.set_header_desc(header_desc)
Example #15
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()
Example #16
0
    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.registerfacade(ClientFacade())
        server.registerfacade(ServerFacade())

        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)