Hola amigos, estoy utilizando Sockets para intercambiar mensajes y datos entre dos aplicaciones, el asunto es que cuando ejecuto el cliente la aplicacion se me cuelga. Del lado del servidor no hay problemas, cuando se establece la conexion el servidor la reconoce, pero nada mas, el codigo es mas o menos el siguiente:
Código:
final JMenuItem buscarMenu = new JMenuItem();
buscarMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
cliente.ejecutarCliente(); // de aqui no pasa
cliente.enviarDatos("Hola Servidor");
}
});
//la clase cliente tiene la siguiente estructura
public Cliente( String host )
{
servidor = host;
}
public void ejecutarCliente()
{
try {
conectarAServidor();
obtenerFlujos();
procesarConexion();
}
catch ( EOFException excepcionEOF ) {
//Mostrar mensaje que se termino la conexion
}
catch ( IOException excepcionES ) {
excepcionES.printStackTrace();
}
finally {
cerrarConexion();
}
}
private void conectarAServidor() throws IOException
{
cliente = new Socket( InetAddress.getByName( servidor ), 12345 );
}
private void obtenerFlujos() throws IOException
{
salida = new ObjectOutputStream( cliente.getOutputStream() );
salida.flush();
entrada = new ObjectInputStream( cliente.getInputStream() );
}
public void enviarDatos( String mensaje )
{
try {
salida.writeObject(mensaje);
salida.flush();
}
catch ( IOException excepcionES ) {
}
}
private void procesarConexion() throws IOException
{
do {
try {
mensaje = ( String ) entrada.readObject();
//aun no tengo definido que voy a hacer con los mensajes
}
catch ( ClassNotFoundException excepcionClaseNoEncontrada ) {
}
} while ( !mensaje.equals( "END" ) );
}
private void cerrarConexion()
{
try {
salida.close();
entrada.close();
cliente.close();
}
catch( IOException excepcionES ) {
excepcionES.printStackTrace();
}
}
public String getServidor() {
return servidor;
}
public void setServidor(String servidor) {
this.servidor = servidor;
}