-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcallResponse.py
51 lines (39 loc) · 1.25 KB
/
callResponse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Copyright (c) 2017-2022 Mathias Funk
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php
import time
from oocsi import OOCSI
def respondToEvent(response):
# set data field in the response
response['newColor'] = int(response['oldColor']) + 1
# play with this delay to let the caller time out
# time.sleep(4)
# start responder OOCSI client
# responder = OOCSI('callResponseResponder', 'localhost')
responder = OOCSI()
print(responder.handle)
# register responder
responder.register('colorChannel', 'colorGenerator', respondToEvent)
### test colorGenerator with two calls
# start caller OOCSI client
#caller = OOCSI('callResponseSender', 'localhost')
caller = OOCSI()
print(caller.handle)
# asynchronous call
call1 = caller.call('colorChannel', 'colorGenerator', {'oldColor': 9}, 1)
# wait for 1 sec
time.sleep(1)
# check response in call object
if 'response' in call1:
print(call1['response'])
else:
print('response not found')
# blocking call
call2 = caller.callAndWait('colorChannel', 'colorGenerator', {'oldColor': 19}, 1)
# check response in call object directly
if 'response' in call2:
print(call2['response'])
else:
print('response not found')
caller.stop()
responder.stop()