forked from 2minchul/conectus-user-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharptest.py
More file actions
37 lines (28 loc) · 908 Bytes
/
arptest.py
File metadata and controls
37 lines (28 loc) · 908 Bytes
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
import asyncio
from pubmarine import PubPen
class Client:
def __init__(self, pubpen):
self.pubpen = pubpen
self.pubpen.subscribe('server_msg', self.display)
def display(self, message):
print(message)
async def send_message(self):
for num in range(0, 5):
print('message: {}'.format(num))
await asyncio.sleep(2)
class Server:
def __init__(self, pubpen):
self.pubpen = pubpen
self.beats = 0
self.pubpen.loop.call_later(1, self.heartbeat)
def heartbeat(self):
self.pubpen.emit('server_msg', self.beats)
self.beats += 1
self.pubpen.loop.call_later(1, self.heartbeat)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
pubpen = PubPen(loop)
server = Server(pubpen)
client = Client(pubpen)
loop.run_until_complete(client.send_message())
loop.close()