elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 01:30  


Tema destacado: ¡Aprende hacking con práctica! - WarZone, el wargame de elhacker.net

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java (Moderadores: Debci, Leyer)
| | | |-+  cliente del socket (ayuda)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: cliente del socket (ayuda)  (Leído 478 veces)
andaluz

Desconectado Desconectado

Mensajes: 266



Ver Perfil
cliente del socket (ayuda)
« en: 1 Abril 2011, 23:36 »

Hola a todos, me gustaria que me ayudaseis a encontrar el fallo que tiene este codigo, me salta la excepcion del primer catch, esta:

this.txa_cliente_B.append("1. Error de E/S con excepcion: "+ex);

y la verdad es que nose cual es el error que tiene el codigo, aver si me pueden ayudar a encontrarlo.

Código
import java.io.*;
public class Cliente_B extends javax.swing.JFrame {
   /** Creates new form Cliente_B */
   java.net.Socket sck;
   java.io.DataInputStream dis;
   java.io.DataOutputStream dos;
   java.io.BufferedReader br;
   java.io.File fich_B;
 
   String mensaje_B, enviar;
 
   public Cliente_B() {
       initComponents();
 
       try
       {
           //sck=new java.net.Socket("localhost", this.txt_puerto_cliente_A.getText());
           sck=new java.net.Socket("localhost", 9902);//"aqui va el puerto"
           dis=new java.io.DataInputStream(sck.getInputStream());
           dos=new java.io.DataOutputStream(sck.getOutputStream());
       }
       catch(IOException ex)
       {
           this.txa_cliente_B.append("1. Error de E/S con excepcion: "+ex);
       }
   }
 
@SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
   private void initComponents() {
 
       lbl_titulo_cliente = new javax.swing.JLabel();
       lbl_puerto_cliente_B = new javax.swing.JLabel();
       lbl_ruta_cliente_B = new javax.swing.JLabel();
       txt_ruta_cliente_B = new javax.swing.JTextField();
       txt_puerto_cliente_B = new javax.swing.JTextField();
       jScrollPane1 = new javax.swing.JScrollPane();
       txa_cliente_B = new javax.swing.JTextArea();
       btn_enviar_cliente_B = new javax.swing.JButton();
       btn_recibir_cliente_B = new javax.swing.JButton();
 
       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
       lbl_titulo_cliente.setFont(new java.awt.Font("Ubuntu", 3, 24)); // NOI18N
       lbl_titulo_cliente.setForeground(new java.awt.Color(0, 14, 255));
       lbl_titulo_cliente.setText("Cliente B");
 
       lbl_puerto_cliente_B.setText("Puerto:");
 
       lbl_ruta_cliente_B.setText("Ruta fichero:");
 
       txa_cliente_B.setColumns(20);
       txa_cliente_B.setRows(5);
       jScrollPane1.setViewportView(txa_cliente_B);
 
       btn_enviar_cliente_B.setText("Enviar");
       btn_enviar_cliente_B.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               btn_enviar_cliente_BActionPerformed(evt);
           }
       });
 
       btn_recibir_cliente_B.setText("Recibir");
       btn_recibir_cliente_B.addActionListener(new java.awt.event.ActionListener() {
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               btn_recibir_cliente_BActionPerformed(evt);
           }
       });
 
       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGap(152, 152, 152)
               .addComponent(lbl_titulo_cliente)
               .addContainerGap(156, Short.MAX_VALUE))
           .addGroup(layout.createSequentialGroup()
               .addGap(112, 112, 112)
               .addComponent(btn_enviar_cliente_B)
               .addGap(68, 68, 68)
               .addComponent(btn_recibir_cliente_B)
               .addContainerGap(116, Short.MAX_VALUE))
           .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
               .addGap(59, 59, 59)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                   .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE)
                   .addGroup(layout.createSequentialGroup()
                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(lbl_ruta_cliente_B)
                           .addComponent(lbl_puerto_cliente_B))
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(txt_puerto_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                           .addComponent(txt_ruta_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))))
               .addGap(57, 57, 57))
       );
       layout.setVerticalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGap(27, 27, 27)
               .addComponent(lbl_titulo_cliente)
               .addGap(36, 36, 36)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(lbl_puerto_cliente_B)
                   .addComponent(txt_puerto_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(26, 26, 26)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(lbl_ruta_cliente_B)
                   .addComponent(txt_ruta_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
               .addGap(57, 57, 57)
               .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addGap(36, 36, 36)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                   .addComponent(btn_enviar_cliente_B)
                   .addComponent(btn_recibir_cliente_B))
               .addContainerGap(24, Short.MAX_VALUE))
       );
 
       lbl_puerto_cliente_B.getAccessibleContext().setAccessibleName("null");
       lbl_ruta_cliente_B.getAccessibleContext().setAccessibleName("lbl_ruta_cliente_B");
 
       pack();
   }// </editor-fold>                        
 
   private void btn_enviar_cliente_BActionPerformed(java.awt.event.ActionEvent evt) {                                                    
       // TODO add your handling code here:
       try
       {
           enviar=this.txa_cliente_B.getText();
           dos.writeUTF("\n"+enviar);
           this.txa_cliente_B.append("\nEnviando mensaje ..."+enviar);
 
           dis.close();
           dos.close();
           sck.close();
       }
       catch(IOException ex)
       {
           this.txa_cliente_B.append("2. ERROR de E/S con excepcion: "+ex);
       }
   }                                                    
 
   private void btn_recibir_cliente_BActionPerformed(java.awt.event.ActionEvent evt) {                                                      
       // TODO add your handling code here:
       try
       {
           mensaje_B=dis.readUTF();
           this.txa_cliente_B.append(mensaje_B);
 
           this.txa_cliente_B.append("Fin de transmision ...");
       }
       catch(IOException ex)
       {
           this.txa_cliente_B.append("3. Error de E/S con excepcion"+ex);
       }
   }
 
   public static void main(String args[]) {
       java.awt.EventQueue.invokeLater(new Runnable() {
           public void run() {
               new Cliente_B().setVisible(true);
           }
       });
   }
 
   // Variables declaration - do not modify                    
   private javax.swing.JButton btn_enviar_cliente_B;
   private javax.swing.JButton btn_recibir_cliente_B;
   private javax.swing.JScrollPane jScrollPane1;
   private javax.swing.JLabel lbl_puerto_cliente_B;
   private javax.swing.JLabel lbl_ruta_cliente_B;
   private javax.swing.JLabel lbl_titulo_cliente;
   private javax.swing.JTextArea txa_cliente_B;
   private javax.swing.JTextField txt_puerto_cliente_B;
   private javax.swing.JTextField txt_ruta_cliente_B;
   // End of variables declaration                  
 
}
 

saludos


« Última modificación: 3 Abril 2011, 11:35 por andaluz » En línea
andaluz

Desconectado Desconectado

Mensajes: 266



Ver Perfil
Re: cliente del socket
« Respuesta #1 en: 1 Abril 2011, 23:44 »

ahhh si quereis os pongo el codigo del servidor, solo teneis que pedirlo.


« Última modificación: 2 Abril 2011, 13:48 por andaluz » En línea
andaluz

Desconectado Desconectado

Mensajes: 266



Ver Perfil
Re: cliente del socket
« Respuesta #2 en: 3 Abril 2011, 11:33 »

Alguien que me puede decir cual es el fallo que tiene este codigo ya que por muchas vueltas que le doy no lo encuentro.

Saludos
En línea
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
cliente/servidor socket
Programación Visual Basic
mig5ueles 11 1,061 Último mensaje 22 Enero 2007, 20:47
por mig5ueles
Cliente-Server (Socket)
Programación Visual Basic
ZiroViI 10 1,538 Último mensaje 25 Octubre 2008, 22:34
por ZiroViI
AYUDA CON CLIENTE SOCKET
Programación C/C++
wachi 1 346 Último mensaje 2 Julio 2009, 23:35
por Flakito81
Socket / cliente servidor
Java
danyelk_6u5 4 6,195 Último mensaje 2 Octubre 2009, 23:19
por Debci
socket cliente y servidor c++ / linux
Programación C/C++
d00ze13 0 1,265 Último mensaje 28 Abril 2011, 18:38
por d00ze13
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines