-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
executable file
·48 lines (32 loc) · 1.04 KB
/
client.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
#!/usr/bin/env python3
'''
Created on 20170119
Update on 20220921
@author: Eduardo Pagotto
'''
import time
import logging
import common
from Zero import SocketFactoryClient
from Zero import Protocol, ProtocolCode
def main():
log = logging.getLogger('Client')
logging.getLogger('Zero').setLevel(logging.INFO)
try:
protocol = Protocol(SocketFactoryClient(common.ADDRESS).create_socket().getSocket())
log.info(protocol.handShake())
protocol.sendString(ProtocolCode.COMMAND, 'ola 123')
idval, msg = protocol.receiveString()
log.info('Recebido id:%s msg:%s', str(idval), msg)
time.sleep(5)
protocol.sendString(ProtocolCode.ERRO, 'Erro Critico')
idVal, msg = protocol.receiveString()
log.info('Recebido id:%s msg:%s', idVal, msg)
protocol.sendClose('Bye-Bye')
log.info('Desconectado')
except Exception as exp:
log.exception('Falha %s', str(exp))
log.info('App desconectado')
if __name__ == '__main__':
common.enable_log()
main()