-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcliente.py
41 lines (33 loc) · 965 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
40
41
__author__ = 'raul'
def cursor():
sys.stdout.write(">: ")
sys.stdout.flush()
import socket, select, sys
cliente = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
cliente.settimeout(2)
print "Ingrese su nick para el chat : "
user = raw_input()
try:
cliente.connect(("localhost",6969))
cliente.send(user)
except:
print "No se pudo establecer la conexion"
sys.exit()
print "Bienvenido a la sala de chat %s " %user
cursor()
while 1:
socketList = [sys.stdin, cliente]
read_sockets, write_sockets, error_sockets = select.select(socketList, [], [])
for sock in read_sockets:
if sock == cliente:
data = sock.recv(4096)
if not data:
print "\nDesconectado del servidor"
sys.exit()
else:
sys.stdout.write(data)
cursor()
else:
msg = sys.stdin.readline()
cliente.send(msg)
cursor()