Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # RECUERDEN LA IDENTACION SI IMPORTA.
- # NO ES LO MISMO UN TAB QUE UN ESPACIO.
- # OPTEN SIEMPRE POR UNO NO LOS DOS.
- import socket # biblioteca con todo lo necesario para manejar sockets
- sc = socket.socket() # instanciamos un objeto del tipo socket
- sc.connect(("localhost", 9998)) #fijamos la ip y el puerto donde el cliente se conectara
- def nombre_funcion(mensaje): #definimos una funcion
- return mensaje
- while True: # while infinito para interactuar constantemente con el servidor
- num = raw_input("Primer numero: ") # recibimos por teclado
- if num == "quit":
- sc.send(num)
- break
- op = raw_input("Operador: ")
- num2 = raw_input("Segundo numero: ")
- mensaje = num + " " + op + " " + num2
- print nombre_funcion(mensaje)
- sc.send(mensaje) #enviamos mensaje al servidor
- resp = sc.recv(1024) # recibimos respuesta del servidor
- print "Resultado %d" % int(resp) #imprimimos respuesta del servidor
- print "adios"
- sc.shutdown(socket.SHUT_RD | socket.SHUT_WR)
- sc.close() #cerramos la conexion
Advertisement
Add Comment
Please, Sign In to add comment