• Miércoles 24 de Abril de 2024, 09:02

Autor Tema:  Ayuda Con El Servidor  (Leído 1455 veces)

edurne

  • Miembro activo
  • **
  • Mensajes: 35
    • Ver Perfil
Ayuda Con El Servidor
« en: Jueves 3 de Febrero de 2005, 10:26 »
0
Esto es una locura para mi!!! sigo atascada haciendo el servidor. Soy la novata por excelencia!!! estoy probando con distintos códigos, intentando hacer cosillas, pero es imposible. Ande meto  la instrucción Thread(gropu=None, target=None, name=None, args=(), kwargs={})????? qué hago con el target???
Los manuales no me dicen nada, estoy empezando a odiar esto!!!!
Esto es lo que tengo:

import SocketServer
import thread
import threading

class BaseRequestHandler(SocketServer.BaseRequestHandler):
   def handle(self):
      print 'la direccion del cliente es:', self.client_address
      print 'el servidor al que se ha conectado es:', self.server
      print self.request
      fichero=open('servidor.txt', 'w')
      self.request.send('ehlo\n')
      fichero.write('ehlo\n')
      b=self.request.recv(128)      
      fichero.write(B)
      fichero.close()
      print'el contenido de la conversaci�n con el servidor es:'
      fichero=open('servidor.txt', 'r')
      for line in fichero.readlines():
         print line
      fichero.close()   

class Threading(threading.Thread):
   def __init__(self):
      threading.Thread.__init__(self)      
   def run(self):      
      print 'el nombre del thread1 es:', thread1.getName()
      print 'el nombre del thread2 es:', thread2.getName()
      print 'el nombre del thread3 es:', thread3.getName()
      print 'el nombre del thread4 es:', thread4.getName()
      print 'threading active count:', threading.activeCount()
      print "the thread1's daemon flag is:", thread1.isDaemon()
      print "the thread2's daemon flag is:", thread2.isDaemon()
      print "the thread3's daemon flag is:", thread3.isDaemon()
      print "the thread4's daemon flag is:", thread4.isDaemon()
      print 'el thread1 esta:1 vivo, 0 muerto -->', thread1.isAlive()
      print 'el thread2 esta:1 vivo, 0 muerto -->', thread2.isAlive()         
      print 'el thread3 esta:1 vivo, 0 muerto -->', thread3.isAlive()
      print 'el thread4 esta:1 vivo, 0 muerto -->', thread4.isAlive()
while 1:
   thread1=Threading()   
   thread2=Threading()   
   thread3=Threading()   
   thread4=Threading()
   thread1.start()
   thread2.start()
   thread3.start()
   thread4.start()
   thread1.join()
   thread2.join()   
   thread3.join()   
   thread4.join()
   server=SocketServer.TCPServer(('',2222), BaseRequestHandler)
   server.serve_forever()

y esto es lo que sale nada más importar el módulo:
el nombre del thread1 es: Thread-15
el nombre del thread2 es: Thread-16
el nombre del thread3 es: Thread-17
el nombre del thread4 es: Thread-18
threading active count: 5
the thread1's daemon flag is: 0
the thread2's daemon flag is: 0
the thread3's daemon flag is: 0
the thread4's daemon flag is: 0
el thread1 esta:1 vivo, 0 muerto --> 1
el thread2 esta:1 vivo, 0 muerto --> 1
el thread3 esta:1 vivo, 0 muerto --> 1
el thread4 esta:1 vivo, 0 muerto --> 1
el nombre del thread1 es: Thread-15
el nombre del thread2 es: Thread-16
el nombre del thread3 es: Thread-17
el nombre del thread4 es: Thread-18
threading active count: 4
the thread1's daemon flag is: 0
the thread2's daemon flag is: 0
the thread3's daemon flag is: 0
the thread4's daemon flag is: 0
el thread1 esta:1 vivo, 0 muerto --> 0
el thread2 esta:1 vivo, 0 muerto --> 1
el thread3 esta:1 vivo, 0 muerto --> 1
el thread4 esta:1 vivo, 0 muerto --> 1
el nombre del thread1 es: Thread-15
el nombre del thread2 es: Thread-16
el nombre del thread3 es: Thread-17
el nombre del thread4 es: Thread-18
threading active count: 3
the thread1's daemon flag is: 0
the thread2's daemon flag is: 0
the thread3's daemon flag is: 0
the thread4's daemon flag is: 0
el thread1 esta:1 vivo, 0 muerto --> 0
el thread2 esta:1 vivo, 0 muerto --> 0
el thread3 esta:1 vivo, 0 muerto --> 1
el thread4 esta:1 vivo, 0 muerto --> 1
el nombre del thread1 es: Thread-15
el nombre del thread2 es: Thread-16
el nombre del thread3 es: Thread-17
el nombre del thread4 es: Thread-18
threading active count: 2
the thread1's daemon flag is: 0
the thread2's daemon flag is: 0
the thread3's daemon flag is: 0
the thread4's daemon flag is: 0
el thread1 esta:1 vivo, 0 muerto --> 0
el thread2 esta:1 vivo, 0 muerto --> 0
el thread3 esta:1 vivo, 0 muerto --> 0
el thread4 esta:1 vivo, 0 muerto --> 1



y luego, cuando me conecto al supuesto servidor, solo me sale esto:

la direccion del cliente es: ('127.0.0.1', 39561)
el servidor al que se ha conectado es: <SocketServer.TCPServer instance at 0x81155ac>
<socket object, fd=15, family=2, type=1, protocol=0>
el contenido de la conversación con el servidor es:
ehlo

ehlo

 y yo lo que quiero es: que pueda conectarme de varios sitios a la vez. Se supone que para eso se usan los threads, no????
Voy a mandar este lenguaje y la informática en general a la..........Qué horror!
Una ayudita, por favor....
Mil gracias, Edurne.