Last change
on this file since 076e15b was
076e15b,
checked in by Alvaro Neira Ayuso <alvaroneay@…>, 5 years ago
|
Modify Client state to use enum
During our connections, we are using states to control the Client Socket. We
defined using global variables. In case that we modify this global variable,
we need to change it in serveral parts of the code.
Using enums and declaring a new class, we can redefine the values or create new
states without changing the same code in differents python files.
|
-
Property mode set to
100644
|
File size:
883 bytes
|
Line | |
---|
1 | from src.ogClient import *
|
---|
2 | from src.ogConfig import *
|
---|
3 |
|
---|
4 | def main():
|
---|
5 | ogconfig = ogConfig()
|
---|
6 | if (not ogconfig.parserFile('cfg/ogagent.cfg')):
|
---|
7 | print 'Error: Parsing configuration file'
|
---|
8 | return 0
|
---|
9 |
|
---|
10 | ip = ogconfig.getValueSection('opengnsys', 'ip')
|
---|
11 | port = ogconfig.getValueSection('opengnsys', 'port')
|
---|
12 |
|
---|
13 | client = ogClient(ip, int(port))
|
---|
14 | client.connect()
|
---|
15 |
|
---|
16 | while 1:
|
---|
17 | sock = client.get_socket()
|
---|
18 | state = client.get_state()
|
---|
19 |
|
---|
20 | if state == State.CONNECTING:
|
---|
21 | readset = [ sock ]
|
---|
22 | writeset = [ sock ]
|
---|
23 | else:
|
---|
24 | readset = [ sock ]
|
---|
25 | writeset = [ ]
|
---|
26 |
|
---|
27 | readable, writable, exception = select.select(readset, writeset, [ ])
|
---|
28 | if state == State.CONNECTING and sock in writable:
|
---|
29 | client.connect2()
|
---|
30 | elif state == State.RECEIVING and sock in readable:
|
---|
31 | client.receive()
|
---|
32 | else:
|
---|
33 | print "bad state" + str(state)
|
---|
34 |
|
---|
35 | if __name__ == "__main__":
|
---|
36 | main()
|
---|
Note: See
TracBrowser
for help on using the repository browser.