-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcliente.py
39 lines (29 loc) · 971 Bytes
/
cliente.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
import socket
import threading
class Cliente():
"""docstring for Cliente"""
name=input("usuario:")
def __init__(self, host="192.168.43.253", port=31337,name=name):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((str(host), int(port)))
msg_recv = threading.Thread(target=self.msg_recv)
msg_recv.daemon = True
msg_recv.start()
while True:
msg = input('->')
if msg != 'salir' :
self.send_msg(name+":"+msg)
else:
self.sock.close()
sys.exit()
def msg_recv(self):
while True:
try:
data = self.sock.recv(1024)
if data:
print(str(data,"utf-8"))
except:
pass
def send_msg(self, msg):
self.sock.send(str.encode(msg,"utf-8"))
c = Cliente()