-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtut53serverbasico.py
More file actions
32 lines (20 loc) · 902 Bytes
/
Copy pathtut53serverbasico.py
File metadata and controls
32 lines (20 loc) · 902 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
32
#Chelin Tutorials 2011 All Rights Reserved.
#Socket Server Basico
import SocketServer #importo el modulo del server
#creo la clase Handler
class MiTcpHandler(SocketServer.BaseRequestHandler):
#se va a llamar en cada coneccion
def handle(self):
self.oracion= self.request.recv(1024).strip() #recibo data
self.num = len(self.oracion)# cuento los caracters "1234abc" self.num = 7
print "La oracion recv es ", self.oracion , " el num de chars " , self.num
self.request.send(str(self.num)) #le mando el numero de caracteres
def main():
print "Tutorial 53 Servidores"
host ="localhost" #direccion
port = 9999
#creo el servidor
server1 = SocketServer.TCPServer((host,port),MiTcpHandler)
print "server corriendo"
server1.serve_forever() # ande hasta q cierre el programa
main()