pilas.red

Package pilas :: Module red |
[hide private]
[frames] | no frames]

# Source Code for Module pilas.red

     1  # -*- encoding: utf-8 -*-
     2  # pilas engine - a video game framework.
     3  #
     4  # copyright 2010 - hugo ruscitti
     5  # license: lgplv3 (see http://www.gnu.org/licenses/lgpl.html)
     6  #
     7  # website - http://www.pilas-engine.com.ar
     8
     9  import SocketServer
    10
    11
    12
    13 -def iniciar_servidor():
    14
    15
    16      class EchoRequestHandler(SocketServer.BaseRequestHandler ):
    17          def setup(self):
    18              print self.client_address, 'connected!'
    19              self.request.send('hi ' + str(self.client_address) + '\n')
    20
    21          def handle(self):
    22              data = 'dummy'
    23              while data:
    24                  data = self.request.recv(1024)
    25                  print "ha llegado el mensaje:", data
    26                  self.request.send(data)
    27
    28                  if data.strip() == 'bye':
    29                      return
    30
    31          def finish(self):
    32              print self.client_address, 'disconnected!'
    33              self.request.send('bye ' + str(self.client_address) + '\n')
    34
    35
    36      #server host is a tuple ('host', port)
    37      puerto = 50008
    38      print "iniciando el modo servidor en el puerto %d" %(puerto)
    39
    40      servidor = SocketServer.ThreadingTCPServer(('', puerto), EchoRequestHandler)
    41      servidor.serve_forever()
    42