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