Commit c252db7654af495651216efda92166f7b75af357
1 parent
ca2504aa
Exists in
dev
Test maintenant simple car lance automatiquement le serveur (simulateur
tele) comme un thread
Showing
8 changed files
with
98 additions
and
13 deletions
Show diff stats
... | ... | @@ -0,0 +1 @@ |
1 | +/client.log | ... | ... |
sockets_tele/README.txt
... | ... | @@ -44,13 +44,16 @@ Pour lancer le client sur le "simulateur" de telescope (localhost, port 11110): |
44 | 44 | |
45 | 45 | |
46 | 46 | ******************************************************************************************** |
47 | -Pour lancer les tests: | |
48 | -- dans un terminal, lancer le simulateur: ./server_run.py | |
49 | -- dans un autre terminal, lancer les tests client: | |
47 | +Pour lancer les TESTS: | |
50 | 48 | cd test/ |
51 | 49 | ./test_client_gemini.py |
52 | 50 | |
53 | -******************************************************************************************** | |
51 | +Ca doit se terminer par quelque chose comme: | |
52 | +Ran 1 test in 0.005s | |
53 | +OK | |
54 | + | |
55 | +Là, il faut arrêter avec CTRL-C (car je ne sais pas encore comment arrêter le serveur simulateur autrement !) | |
56 | + | |
54 | 57 | |
55 | 58 | |
56 | 59 | ... | ... |
sockets_tele/src/client/socket_client_abstract.py
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | |
3 | -import socket | |
3 | +"""Socket Client (abstract) implementation | |
4 | + | |
5 | +To be used as a base class (interface) for any concrete socket client class | |
6 | +""" | |
7 | + | |
8 | + | |
9 | +# Standard library imports | |
4 | 10 | import logging |
11 | +import socket | |
12 | + | |
13 | +# Third party imports | |
14 | +# None | |
15 | + | |
16 | +# Local application imports | |
17 | +# None | |
18 | + | |
19 | + | |
20 | + | |
5 | 21 | |
6 | 22 | logger = None |
7 | 23 | # Aliases for logger: | ... | ... |
sockets_tele/src/client/socket_client_telescope_abstract.py
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | |
3 | -import socket | |
3 | +"""Socket Client Telescope (abstract) implementation | |
4 | + | |
5 | +To be used as a base class (interface) for any concrete socket client telescope class | |
6 | +""" | |
7 | + | |
8 | + | |
9 | +# Standard library imports | |
4 | 10 | import logging |
11 | +import socket | |
5 | 12 | |
13 | +# Third party imports | |
14 | +# None | |
15 | + | |
16 | +# Local application imports | |
6 | 17 | #sys.path.append('../..') |
7 | 18 | #from src.client.socket_client_abstract import UnknownCommandException, SocketClientAbstract |
8 | 19 | from src.client.socket_client_abstract import * |
9 | 20 | |
10 | 21 | |
11 | 22 | |
23 | + | |
24 | + | |
25 | + | |
12 | 26 | class Position(): |
13 | 27 | x = 0 |
14 | 28 | y = 0 | ... | ... |
sockets_tele/src/client/socket_client_telescope_gemini.py
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | |
3 | -import socket | |
4 | -import logging | |
5 | -import sys | |
3 | +"""Socket Client GEMINI Telescope implementation | |
6 | 4 | |
5 | +To be used as a concrete class to system control a GEMINI telescope | |
6 | +""" | |
7 | + | |
8 | + | |
9 | +# Standard library imports | |
10 | +#import socket | |
11 | +#import logging | |
12 | +#import sys | |
13 | + | |
14 | +# Third party imports | |
15 | +# None | |
16 | + | |
17 | +# Local application imports | |
7 | 18 | #sys.path.append('../..') |
8 | 19 | from src.client.socket_client_telescope_abstract import Position, UnknownCommandException, SocketClientTelescopeAbstract |
9 | 20 | |
10 | 21 | |
22 | + | |
23 | +TERMINATOR = '\x00' | |
24 | + | |
25 | + | |
11 | 26 | class SocketClientTelescopeGEMINI(SocketClientTelescopeAbstract): |
12 | 27 | |
13 | 28 | ''' | ... | ... |
sockets_tele/src/server/server_udp_or_tcp.py
... | ... | @@ -2,8 +2,24 @@ |
2 | 2 | |
3 | 3 | # cf https://docs.python.org/3/library/socketserver.html#socketserver-tcpserver-example |
4 | 4 | |
5 | +"""Socket Server implementation | |
6 | + | |
7 | +To be used as a minimalist telescope simulator to which a socket client (SocketClient) can connect | |
8 | +""" | |
9 | + | |
10 | +# Standard library imports | |
5 | 11 | import socketserver |
6 | 12 | |
13 | +# Third party imports | |
14 | +# None | |
15 | + | |
16 | +# Local application imports | |
17 | +# None | |
18 | + | |
19 | + | |
20 | + | |
21 | + | |
22 | + | |
7 | 23 | ###STAMP = '01000000' |
8 | 24 | #STAMP = '0100000000000000' |
9 | 25 | #HOST, PORT = "localhost", 11110 | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +/client.log | ... | ... |
sockets_tele/test/test_client_gemini.py
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | |
3 | +import threading | |
4 | + | |
3 | 5 | import unittest |
4 | 6 | |
5 | 7 | import sys |
6 | 8 | sys.path.append('..') |
9 | +from src.server.server_udp_or_tcp import get_SocketServer_UDP_TCP | |
7 | 10 | from src.client.socket_client_telescope_gemini import SocketClientTelescopeGEMINI |
8 | 11 | |
12 | +#HOST, PORT = "localhost", 9999 | |
13 | +#HOST, PORT = "localhost", 20001 | |
14 | +HOST, PORT = "localhost", 11110 | |
9 | 15 | |
10 | 16 | class TestClient(unittest.TestCase): |
11 | 17 | |
18 | + | |
12 | 19 | def setUp(self): |
13 | 20 | self.seq = range(10) |
14 | 21 | |
15 | - def test_run(self): | |
22 | + def server(self): | |
23 | + with get_SocketServer_UDP_TCP(HOST, PORT, "UDP") as myserver: | |
24 | + myserver.serve_forever() | |
16 | 25 | |
17 | - #HOST, PORT = "localhost", 9999 | |
18 | - #HOST, PORT = "localhost", 20001 | |
19 | - HOST, PORT = "localhost", 11110 | |
26 | + def test_run(self): | |
20 | 27 | |
21 | 28 | qa = [ |
22 | 29 | (':toto#', 'TOTO'), |
... | ... | @@ -24,6 +31,13 @@ class TestClient(unittest.TestCase): |
24 | 31 | #(':GD#', '+12:28') |
25 | 32 | ] |
26 | 33 | |
34 | + #TODO: RUN SERVER in a thread | |
35 | + t_server = threading.Thread(target=self.server) | |
36 | + #threads.append(t) | |
37 | + t_server.start() | |
38 | + #time.sleep(3) | |
39 | + | |
40 | + # RUN CLIENT to connect to server | |
27 | 41 | #tsock = SocketClient_UDP_TCP(HOST, PORT, "UDP") |
28 | 42 | with SocketClientTelescopeGEMINI(HOST, PORT) as tsock: |
29 | 43 | # Only useful for TCP (does nothing for UDP) |
... | ... | @@ -44,6 +58,11 @@ class TestClient(unittest.TestCase): |
44 | 58 | self.assertEqual(radec, ['15:01:48', '+12:28']) |
45 | 59 | |
46 | 60 | #tsock.close() |
61 | + | |
62 | + #TODO: Stop the server thread (t_server), how can we do that ? | |
63 | + # cf https://www.oreilly.com/library/view/python-cookbook-2nd/0596007973/ch09s03.html | |
64 | + #t_server.suicide_toi() !!! | |
65 | + | |
47 | 66 | |
48 | 67 | if __name__ == '__main__': |
49 | 68 | unittest.main() |
50 | 69 | \ No newline at end of file | ... | ... |