Código del servidor » History » Version 1
Ruben Salas, 01/03/2024 10:27 PM
1 | 1 | Ruben Salas | h2. Código del servidor |
---|---|---|---|
2 | 1 | Ruben Salas | |
3 | 1 | Ruben Salas | #!/usr/bin/env pybricks-micropython |
4 | 1 | Ruben Salas | |
5 | 1 | Ruben Salas | import socket |
6 | 1 | Ruben Salas | from library import * |
7 | 1 | Ruben Salas | s = socket.socket() |
8 | 1 | Ruben Salas | print("Socket creado") |
9 | 1 | Ruben Salas | port = 19999 |
10 | 1 | Ruben Salas | s.bind( ("", port) ) |
11 | 1 | Ruben Salas | print("El socket se creo con puerto:{}".format(port)) |
12 | 1 | Ruben Salas | s.listen(5) |
13 | 1 | Ruben Salas | print("EL socket is listening....") |
14 | 1 | Ruben Salas | connect, addr = s.accept() |
15 | 1 | Ruben Salas | print("Se conecto a {}".format(addr)) |
16 | 1 | Ruben Salas | while True: |
17 | 1 | Ruben Salas | rawByte = connect.recv(1) |
18 | 1 | Ruben Salas | char = rawByte.decode('utf-8') |
19 | 1 | Ruben Salas | if (char == 'w'): |
20 | 1 | Ruben Salas | avanzar() |
21 | 1 | Ruben Salas | if (char == 's'): |
22 | 1 | Ruben Salas | retroceder() |
23 | 1 | Ruben Salas | if (char == 'd'): |
24 | 1 | Ruben Salas | rotarDerecha() |
25 | 1 | Ruben Salas | if (char == 'a'): |
26 | 1 | Ruben Salas | rotarIzquierda() |
27 | 1 | Ruben Salas | if (char == 'p'): |
28 | 1 | Ruben Salas | golpeSuave() |
29 | 1 | Ruben Salas | if (char == 'f'): |
30 | 1 | Ruben Salas | golpeFuerte() |
31 | 1 | Ruben Salas | if (char == 'i'): |
32 | 1 | Ruben Salas | devolverBrazo() |
33 | 1 | Ruben Salas | if (char == ' '): |
34 | 1 | Ruben Salas | detener() |
35 | 1 | Ruben Salas | detenerBrazo() |