Ejemplo n.º 1
0
def ipcTest():
    s = ipc.ServerIPC(
        39188
    )  # I have got the enterprise number for Virtual Cable. This number is not about ports, but as good as any other selection :)

    s.start()

    sleep(1)

    client = ipc.ClientIPC(39188)
    client.start()
    client2 = ipc.ClientIPC(39188)
    client2.start()

    print("Requesting information")
    client.requestInformation()
    print("Sending login info")
    client.sendLogin('user1')
    print("Sending logout info")
    client.sendLogout('mariete' * 1000)

    print('Sending message')
    s.sendMessage(ipc.MSG_LOGOFF, None)
    s.sendMessage(ipc.MSG_MESSAGE, 'Cierra la sesión')
    s.sendMessage(33, 'invalid')
    s.sendMessage(ipc.MSG_SCRIPT, 'print "hello"')
    print('Message sent')

    for c in (client, client2):
        print(c.getMessage())
        print(c.getMessage())
        print(c.getMessage())

    client.stop()
    client.join()

    s.sendMessage(ipc.MSG_LOGOFF, None)
    s.sendMessage(ipc.MSG_MESSAGE, 'Cierra la sesión')
    s.sendMessage(33, 'invalid')
    s.sendMessage(ipc.MSG_SCRIPT, 'print "hello"')

    print(client2.getMessage())
    print(client2.getMessage())
    print(client2.getMessage())

    client2.stop()
    s.stop()
    client2.join()
    s.join()
Ejemplo n.º 2
0
    def __init__(self):
        super(self.__class__, self).__init__()
        # Retries connection for a while
        for _ in range(10):
            try:
                self.ipc = ipc.ClientIPC(IPC_PORT)
                self.ipc.start()
                break
            except Exception:
                logger.debug('IPC Server is not reachable')
                self.ipc = None
                time.sleep(2)

        self.running = False
Ejemplo n.º 3
0
        self.notifyStop()


def usage():
    sys.stderr.write("usage: {} start|stop|restart|login 'username'|logout 'username'\n".format(sys.argv[0]))
    sys.exit(2)

if __name__ == '__main__':
    logger.setLevel(20000)

    if len(sys.argv) == 3 and sys.argv[1] in ('login', 'logout'):
        logger.debug('Running client udsactor')
        client = None
        try:
            client = ipc.ClientIPC(IPC_PORT)
            if 'login' == sys.argv[1]:
                client.sendLogin(sys.argv[2])
                sys.exit(0)
            elif 'logout' == sys.argv[1]:
                client.sendLogout(sys.argv[2])
                sys.exit(0)
            else:
                usage()
        except Exception as e:
            logger.error(e)
    elif len(sys.argv) != 2:
        usage()

    logger.debug('Executing actor')
    daemon = UDSActorSvc()
Ejemplo n.º 4
0
def testServer():

    # Disable verify warinings
    logging.getLogger("requests").setLevel(logging.ERROR)
    urllib3.disable_warnings()  # @UndefinedVariable

    s = ipc.ServerIPC(
        39188
    )  # I have got the enterprise number for Virtual Cable. This number is not about ports, but as good as any other selection :)

    s.start()

    client = ipc.ClientIPC(39188)
    client.start()

    while True:
        try:
            port = random.randrange(32000, 64000)
            server = httpserver.HTTPServerThread(('172.27.0.8', port), s)
            break
        except:
            pass

    serverUrl = server.getServerUrl()
    server.start()

    print(serverUrl)

    res = requests.post(serverUrl + '/message',
                        data=json.dumps({'message': 'Test message'}),
                        headers={'content-type': 'application/json'},
                        verify=False)
    print(res)
    print(res.json())

    res = requests.post(
        serverUrl + '/script',
        data=json.dumps({
            'script':
            'import time\ntime.sleep(1)\nfor v in xrange(10): print "Hello world, this is an script"'
        }),
        headers={'content-type': 'application/json'},
        verify=False)
    print(res)
    print(res.json())

    res = requests.post(serverUrl + '/script',
                        data=json.dumps({
                            'script': 'print "Hello world, this is an script"',
                            'user': True
                        }),
                        headers={'content-type': 'application/json'},
                        verify=False)
    print(res)
    print(res.json())

    res = requests.get(serverUrl + '/information?param1=1&param2=2',
                       headers={'content-type': 'application/json'},
                       verify=False)
    print(res)
    print(res.json())

    print("Messages:")
    print(client.getMessage())
    print(client.getMessage())

    # try:
    #    while True:
    #        Sleep(1000)
    # except:
    #    pass

    server.stop()
    s.stop()
    client.stop()