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