-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathechoServer.py
More file actions
31 lines (26 loc) · 826 Bytes
/
echoServer.py
File metadata and controls
31 lines (26 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
"""
Servidor eco (echo).
un sencillo servidor que devuelve lo que recibe
para ir conociendo como funcionan los sockets.
"""
# Import de módulos de la biblioteca estándar
import socket
# Constantes globales
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
# Código principal
if __name__ == "__main__":
with socket.socket(socket.AF_INET,
socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by',
addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)