Can I make some requests as a method using autobahn?

#1

Hello,

I’m trying to use some service that requires websocket connection. The service works like follows;

  1. Connect the service by websocket

  2. Send ‘register’ request

  3. Send a request to get a new ws address to connect.

  4. Connect with the new ws address

  5. Send ‘click’ request with the coordinates of mouse pointer

I tried to make the above sequence as one method because I needed to generate a lot of clicks. It succeeded when I call it once.

But I realized that it failed when I called it multiple times in a test because the sequence tries to run reactor everytime, and reactor can’t be restarted.

So I made the method as a process like below code. It looked like it almost worked. It usually succeeds, but it sometimes fails, and I can’t figure out the cause.

I know this is a kind of workaround. Can anyone tell me a proper way to achieve my goal? I have attached the entire code for review.

Thank you for reading my question.

class InputEventGenerator(object):

def __init__(self):

    self.hostname = hostname

    self.manifest = manifest

def _click(self, x, y):

    ws_address = 'ws://{0}:3000/'.format(self.hostname)

    factory = PrepareInputEventFactory(ws_address)

    factory.manifest = self.manifest

    parameters = {'x': x, 'y': y, 'is_clicked': True}

    factory.parameters = parameters

    connectWS(factory)

    reactor.run()

def click(self, x, y):

    p = Process(target=self._click, args=[x, y])

    p.start()

    p.join()

    p.terminate()

Usage:

input_event_generator = InputEventGenerator()

input_event_generator.click(320, 160)

… some operations …

    input_event_generator.click(320, 480)

… some operations …

    input_event_generator.click(1000, 200)

excerpt_of_input_event_generator.py (3.21 KB)

0 Likes

#2

Hello,

I'm trying to use some service that requires websocket connection. The
service works like follows;

1. Connect the service by websocket
2. Send 'register' request
3. Send a request to get a new ws address to connect.
4. Connect with the new ws address
5. Send 'click' request with the coordinates of mouse pointer

So this is a _client_ that first connects to WS URI "A", and subsequently to WS URI "B"?

If so, the proper way is to create 2 client factories (since a given instance of a Twisted client factory can reconnect to the same server, but you use a _new_ client factory to connect to another server).

There is no problem in calling `connectWs` later when URI "B" has been received.

/Tobias

···

Am 04.09.2013 15:41, schrieb Chanwoo Yoo:

I tried to make the above sequence as one method because I needed to
generate a lot of clicks. It succeeded when I call it once.

But I realized that it failed when I called it multiple times in a test
because the sequence tries to run reactor everytime, and reactor can't
be restarted.

So I made the method as a process like below code. It looked like it
almost worked. It usually succeeds, but it sometimes fails, and I can't
figure out the cause.

I know this is a kind of workaround. Can anyone tell me a proper way to
achieve my goal? I have attached the entire code for review.

Thank you for reading my question.

class InputEventGenerator(object):

     def __init__(self):
         self.hostname = hostname
         self.manifest = manifest

     def _click(self, x, y):
         ws_address = 'ws://{0}:3000/'.format(self.hostname)
         factory = PrepareInputEventFactory(ws_address)
         factory.manifest = self.manifest
         parameters = {'x': x, 'y': y, 'is_clicked': True}
         factory.parameters = parameters
         connectWS(factory)
         reactor.run()

     def click(self, x, y):
         p = Process(target=self._click, args=[x, y])
         p.start()
         p.join()
         p.terminate()

Usage:

         input_event_generator = InputEventGenerator()
         input_event_generator.click(320, 160)
         ... some operations ...
         input_event_generator.click(320, 480)
         ... some operations ...
         input_event_generator.click(1000, 200)

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Likes