-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.py
40 lines (32 loc) · 954 Bytes
/
Server.py
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
32
33
34
35
36
37
38
39
40
import socket
import threading
Host = "127.0.0.1"
Port = 65432
address = (Host, Port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
with s:
print("Hola, prendiendo")
s.bind(address)
s.listen()
conn, addr = s.accept()
print(f"[ESCUCHANDO] ip {Host} puerto {Port}")
def thread():
try:
while True:
data = conn.recv(1024)
print(f"[Cliente]: {data.decode()}")
if not data:
break
except Exception as e:
print(f"[ERROR]: {e}")
def thread2():
while True:
sm = input("[SERVIDOR]: ")
conn.sendall(sm.encode())
if sm == "Ya no quiero hablar contigo":
conn.close()
print("Se ha cortado la conexión")
break
hola = threading.Thread(target=thread, daemon=True)
hola.start()
thread2()