Servidor » History » Version 1
cristobal hernandez, 12/12/2024 08:33 PM
1 | 1 | cristobal hernandez | h1. Servidor |
---|---|---|---|
2 | 1 | cristobal hernandez | <pre><code class="python"> |
3 | 1 | cristobal hernandez | import socket |
4 | 1 | cristobal hernandez | from funciones_dos import * |
5 | 1 | cristobal hernandez | |
6 | 1 | cristobal hernandez | s = socket.socket() |
7 | 1 | cristobal hernandez | print("Socket creado") |
8 | 1 | cristobal hernandez | port = 8080 |
9 | 1 | cristobal hernandez | s.bind(('', port)) |
10 | 1 | cristobal hernandez | |
11 | 1 | cristobal hernandez | s.listen(5) |
12 | 1 | cristobal hernandez | print("Servidor escuchando en el puerto 8080...") |
13 | 1 | cristobal hernandez | |
14 | 1 | cristobal hernandez | connect, addr = s.accept() |
15 | 1 | cristobal hernandez | print("Conectado con a {} ".format(addr)) |
16 | 1 | cristobal hernandez | |
17 | 1 | cristobal hernandez | while True: |
18 | 1 | cristobal hernandez | rawByte = connect.recv(1) |
19 | 1 | cristobal hernandez | comando = rawByte.decode('utf-8') |
20 | 1 | cristobal hernandez | |
21 | 1 | cristobal hernandez | if comando == 'w': |
22 | 1 | cristobal hernandez | mover_arriba() |
23 | 1 | cristobal hernandez | |
24 | 1 | cristobal hernandez | if comando == 's': |
25 | 1 | cristobal hernandez | mover_atras() |
26 | 1 | cristobal hernandez | |
27 | 1 | cristobal hernandez | if comando == 'a': |
28 | 1 | cristobal hernandez | mover_izquierda() |
29 | 1 | cristobal hernandez | |
30 | 1 | cristobal hernandez | if comando == 'd': |
31 | 1 | cristobal hernandez | mover_derecha() |
32 | 1 | cristobal hernandez | |
33 | 1 | cristobal hernandez | if comando == 'x': |
34 | 1 | cristobal hernandez | atrapar() |
35 | 1 | cristobal hernandez | |
36 | 1 | cristobal hernandez | if comando == 'c': |
37 | 1 | cristobal hernandez | soltar() |
38 | 1 | cristobal hernandez | |
39 | 1 | cristobal hernandez | if comando == 'l': |
40 | 1 | cristobal hernandez | base_subir() |
41 | 1 | cristobal hernandez | |
42 | 1 | cristobal hernandez | if comando == 'k': |
43 | 1 | cristobal hernandez | base_soltar() |
44 | 1 | cristobal hernandez | |
45 | 1 | cristobal hernandez | if comando == ' ': |
46 | 1 | cristobal hernandez | stop() |
47 | 1 | cristobal hernandez | |
48 | 1 | cristobal hernandez | </code></pre> |