elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  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 2,743 veces)
andaluz


Desconectado Desconectado

Mensajes: 333



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

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
  1. import java.io.*;
  2. public class Cliente_B extends javax.swing.JFrame {
  3.    /** Creates new form Cliente_B */
  4.    java.net.Socket sck;
  5.    java.io.DataInputStream dis;
  6.    java.io.DataOutputStream dos;
  7.    java.io.BufferedReader br;
  8.    java.io.File fich_B;
  9.  
  10.    String mensaje_B, enviar;
  11.  
  12.    public Cliente_B() {
  13.        initComponents();
  14.  
  15.        try
  16.        {
  17.            //sck=new java.net.Socket("localhost", this.txt_puerto_cliente_A.getText());
  18.            sck=new java.net.Socket("localhost", 9902);//"aqui va el puerto"
  19.            dis=new java.io.DataInputStream(sck.getInputStream());
  20.            dos=new java.io.DataOutputStream(sck.getOutputStream());
  21.        }
  22.        catch(IOException ex)
  23.        {
  24.            this.txa_cliente_B.append("1. Error de E/S con excepcion: "+ex);
  25.        }
  26.    }
  27.  
  28. @SuppressWarnings("unchecked")
  29.    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  30.    private void initComponents() {
  31.  
  32.        lbl_titulo_cliente = new javax.swing.JLabel();
  33.        lbl_puerto_cliente_B = new javax.swing.JLabel();
  34.        lbl_ruta_cliente_B = new javax.swing.JLabel();
  35.        txt_ruta_cliente_B = new javax.swing.JTextField();
  36.        txt_puerto_cliente_B = new javax.swing.JTextField();
  37.        jScrollPane1 = new javax.swing.JScrollPane();
  38.        txa_cliente_B = new javax.swing.JTextArea();
  39.        btn_enviar_cliente_B = new javax.swing.JButton();
  40.        btn_recibir_cliente_B = new javax.swing.JButton();
  41.  
  42.        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  43.  
  44.        lbl_titulo_cliente.setFont(new java.awt.Font("Ubuntu", 3, 24)); // NOI18N
  45.        lbl_titulo_cliente.setForeground(new java.awt.Color(0, 14, 255));
  46.        lbl_titulo_cliente.setText("Cliente B");
  47.  
  48.        lbl_puerto_cliente_B.setText("Puerto:");
  49.  
  50.        lbl_ruta_cliente_B.setText("Ruta fichero:");
  51.  
  52.        txa_cliente_B.setColumns(20);
  53.        txa_cliente_B.setRows(5);
  54.        jScrollPane1.setViewportView(txa_cliente_B);
  55.  
  56.        btn_enviar_cliente_B.setText("Enviar");
  57.        btn_enviar_cliente_B.addActionListener(new java.awt.event.ActionListener() {
  58.            public void actionPerformed(java.awt.event.ActionEvent evt) {
  59.                btn_enviar_cliente_BActionPerformed(evt);
  60.            }
  61.        });
  62.  
  63.        btn_recibir_cliente_B.setText("Recibir");
  64.        btn_recibir_cliente_B.addActionListener(new java.awt.event.ActionListener() {
  65.            public void actionPerformed(java.awt.event.ActionEvent evt) {
  66.                btn_recibir_cliente_BActionPerformed(evt);
  67.            }
  68.        });
  69.  
  70.        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  71.        getContentPane().setLayout(layout);
  72.        layout.setHorizontalGroup(
  73.            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74.            .addGroup(layout.createSequentialGroup()
  75.                .addGap(152, 152, 152)
  76.                .addComponent(lbl_titulo_cliente)
  77.                .addContainerGap(156, Short.MAX_VALUE))
  78.            .addGroup(layout.createSequentialGroup()
  79.                .addGap(112, 112, 112)
  80.                .addComponent(btn_enviar_cliente_B)
  81.                .addGap(68, 68, 68)
  82.                .addComponent(btn_recibir_cliente_B)
  83.                .addContainerGap(116, Short.MAX_VALUE))
  84.            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  85.                .addGap(59, 59, 59)
  86.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  87.                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 293, Short.MAX_VALUE)
  88.                    .addGroup(layout.createSequentialGroup()
  89.                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  90.                            .addComponent(lbl_ruta_cliente_B)
  91.                            .addComponent(lbl_puerto_cliente_B))
  92.                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
  93.                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  94.                            .addComponent(txt_puerto_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
  95.                            .addComponent(txt_ruta_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))))
  96.                .addGap(57, 57, 57))
  97.        );
  98.        layout.setVerticalGroup(
  99.            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  100.            .addGroup(layout.createSequentialGroup()
  101.                .addGap(27, 27, 27)
  102.                .addComponent(lbl_titulo_cliente)
  103.                .addGap(36, 36, 36)
  104.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  105.                    .addComponent(lbl_puerto_cliente_B)
  106.                    .addComponent(txt_puerto_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  107.                .addGap(26, 26, 26)
  108.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  109.                    .addComponent(lbl_ruta_cliente_B)
  110.                    .addComponent(txt_ruta_cliente_B, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  111.                .addGap(57, 57, 57)
  112.                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
  113.                .addGap(36, 36, 36)
  114.                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  115.                    .addComponent(btn_enviar_cliente_B)
  116.                    .addComponent(btn_recibir_cliente_B))
  117.                .addContainerGap(24, Short.MAX_VALUE))
  118.        );
  119.  
  120.        lbl_puerto_cliente_B.getAccessibleContext().setAccessibleName("null");
  121.        lbl_ruta_cliente_B.getAccessibleContext().setAccessibleName("lbl_ruta_cliente_B");
  122.  
  123.        pack();
  124.    }// </editor-fold>                        
  125.  
  126.    private void btn_enviar_cliente_BActionPerformed(java.awt.event.ActionEvent evt) {                                                    
  127.        // TODO add your handling code here:
  128.        try
  129.        {
  130.            enviar=this.txa_cliente_B.getText();
  131.            dos.writeUTF("\n"+enviar);
  132.            this.txa_cliente_B.append("\nEnviando mensaje ..."+enviar);
  133.  
  134.            dis.close();
  135.            dos.close();
  136.            sck.close();
  137.        }
  138.        catch(IOException ex)
  139.        {
  140.            this.txa_cliente_B.append("2. ERROR de E/S con excepcion: "+ex);
  141.        }
  142.    }                                                    
  143.  
  144.    private void btn_recibir_cliente_BActionPerformed(java.awt.event.ActionEvent evt) {                                                      
  145.        // TODO add your handling code here:
  146.        try
  147.        {
  148.            mensaje_B=dis.readUTF();
  149.            this.txa_cliente_B.append(mensaje_B);
  150.  
  151.            this.txa_cliente_B.append("Fin de transmision ...");
  152.        }
  153.        catch(IOException ex)
  154.        {
  155.            this.txa_cliente_B.append("3. Error de E/S con excepcion"+ex);
  156.        }
  157.    }
  158.  
  159.    public static void main(String args[]) {
  160.        java.awt.EventQueue.invokeLater(new Runnable() {
  161.            public void run() {
  162.                new Cliente_B().setVisible(true);
  163.            }
  164.        });
  165.    }
  166.  
  167.    // Variables declaration - do not modify                    
  168.    private javax.swing.JButton btn_enviar_cliente_B;
  169.    private javax.swing.JButton btn_recibir_cliente_B;
  170.    private javax.swing.JScrollPane jScrollPane1;
  171.    private javax.swing.JLabel lbl_puerto_cliente_B;
  172.    private javax.swing.JLabel lbl_ruta_cliente_B;
  173.    private javax.swing.JLabel lbl_titulo_cliente;
  174.    private javax.swing.JTextArea txa_cliente_B;
  175.    private javax.swing.JTextField txt_puerto_cliente_B;
  176.    private javax.swing.JTextField txt_ruta_cliente_B;
  177.    // End of variables declaration                  
  178.  
  179. }
  180.  

saludos


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

andaluz


Desconectado Desconectado

Mensajes: 333



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

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


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

andaluz


Desconectado Desconectado

Mensajes: 333



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

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 « 1 2 »
Programación Visual Basic
mig5ueles 11 4,697 Último mensaje 22 Enero 2007, 20:47 pm
por mig5ueles
Cliente-Server (Socket) « 1 2 »
Programación Visual Basic
ZiroViI 10 4,552 Último mensaje 25 Octubre 2008, 22:34 pm
por ZiroViI
socket cliente y servidor c++ / linux
Programación C/C++
d00ze13 0 4,703 Último mensaje 28 Abril 2011, 18:38 pm
por d00ze13
[Ayuda - Python] Socket
Scripting
Softrix18 2 2,135 Último mensaje 17 Febrero 2013, 01:22 am
por Softrix18
Python 3.7 socket socket.gaierror errno7 cliente Android.
Scripting
@XSStringManolo 2 2,713 Último mensaje 28 Diciembre 2019, 00:09 am
por @XSStringManolo
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines