Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/08/2007, 10:02
selma128
 
Fecha de Ingreso: diciembre-2003
Mensajes: 190
Antigüedad: 20 años, 5 meses
Puntos: 0
problema con los threads

Hola a todos, tengo un problema con threads que no se resolver. Cuantos threads puedo tener activos a un mismo tiempo?

Estoy practicando con threads y sockets y me he hecho un pequeño programa que sirve para mandar ficheros entre ordenadores. Cada programa es a la vez cliente y servidor

Crea un thread donde esta contenida la logica del programa (el menu, etc)
y otro thread donde esta un socket que atiende las peticiones.

el caso es que por la ejecucion del programa me da la sensacion de que solo se levanta el primer thread y no el segundo ya que ambos tienen system.out para sacar cosas por consola pero solo salen cosas del primer thread y no entiendo que puede estar pasando




import java.net.*;
import java.io.*;
import java.util.*;


public class cliente {

public static void main(String[] args) throws Exception {


// Which port should we listen to
int port = 5000;
// Which address
String group = "225.4.5.6";
String ipServidor;
int puertoClienteServidor; //contiene el puerto recibido por multicast para comunicarnos con el servidor
int PuertoClienteCliente = 6000;


// Create the socket and bind it to port 'port'.
MulticastSocket s = new MulticastSocket(port);

// join the multicast group
s.joinGroup(InetAddress.getByName(group));
// Now the socket is set up and we are ready to receive packets

// Create a DatagramPacket and do a receive
byte buf[] = new byte[1024];

System.out.println("Conectandose a la red. Esperando anuncio de servidor");
DatagramPacket pack = new DatagramPacket(buf, buf.length);
s.receive(pack);

String received = new String(pack.getData());

ipServidor = received.substring(0,received.indexOf("/",0));
puertoClienteServidor = Integer.parseInt(received.substring(received.index Of("/",0)+1, received.length()).trim());
System.out.println("Recibido mensaje de anuncio de servidor desde " + ipServidor + " y puerto " + puertoClienteServidor);

//creamos el socket con el servidor para conectarnos a el y enviarle nuestros archivos
Socket soc=new Socket(ipServidor, puertoClienteServidor);

//socket por donde atiende el cliente a otros clientes (transf archivos)
ServerSocket Clientsoc = new ServerSocket(PuertoClienteCliente);


// And when we have finished receiving data leave the multicast group and
// close the socket
s.leaveGroup(InetAddress.getByName(group));
s.close();

transferfileClient t=new transferfileClient(soc, PuertoClienteCliente);


while(true) //cuando llegue una peticion de transferencia de archivo arrancara un hilo
{
System.out.println("Esperando la conexion numero ");
EscucharPeticiones p = new EscucharPeticiones(Clientsoc.accept());
System.out.println("enviando€MMMMMMMM " );
}


}
}