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

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Mensajes
Páginas: [1] 2 3
1  Programación / Programación C/C++ / Re: problema con la funcion select(); en: 29 Julio 2010, 09:22 am
No, lo del FD_ISSET, está bien, lo que está mal es la condición de detección de que se han desconectado desde el otro extremo de la conexión:

Citar
               if(strlen(buffer)==1){
                     printf("\n>>>>> nos desconectan...\n\t Adios\n");


Como te expliqué en el post anterior, cuando se cierra el socket desde el otro extremo, el tamaño de lo leído por read es 0, no 1.
Si te fijas estás cerrando todo el rato el socket desde el server (haces un close después de un read en el server), y como esta condición está mal se queda en el bucle, prueba a cambiar ese 1 por un 0.

Y ahora ya una cosa personal, por favor, si yo te respondo sin faltas de ortografía agradecería que me respondieras sin ellas. Un saludo.
2  Programación / Programación C/C++ / Re: problema con la funcion select(); en: 28 Julio 2010, 19:30 pm

Te salta el evento de lectura en el socket porque tiene que saltar. Me explico.

Para saber si un socket está cerrado, salta un evento de lectura, y al hacer un read se lee una longitud 0. De esta manera podemos saber si el otro extremo de la comunicación ha cerrrado el socket.

En el código del servidor se puede ver cómo cierras el socket nada más hacer un printf, por lo que en el cliente salta el evento de lectura para avisar que está cerrado.

Luego también esté el problema de que la comprobación del cierre del socket está mal, debería de ser 0, no uno O_o y también no tienes pq hacer un strlen del buffer ni un bzero, ya que read este dato (bytes leídos) ya te lo devuelve el read.
3  Programación / Java / Re: Cargar .class(Java) en: 21 Diciembre 2005, 17:42 pm
Para mí la solución mas elegante sería hacer un execve (llamar a la función para ejecutar lo que io quiero) si estamos en un sistema linux; en windows habrá una función parecida en la API del windoze, y en los parámetros le pasas las movidas (el path, los .class)...
Luego lo de instalar la jre... pos en win por defecto viene con una jvm, en linux puedes hacer un execve de un wget (previamente has colgado una jre por ahí ... XD) y yasta, llamas a java con execve. :P

Saludos
4  Programación / Java / Re: Java en: 27 Noviembre 2005, 01:54 am
mmm este esta mucho mas currado:


Código:
import java.awt.AWTEvent;
import java.awt.AWTEventMulticaster;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;

import java.awt.event.MouseEvent;

import java.awt.event.FocusEvent;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * A circular button.
 *
 */

public class CircularButton extends Component
{
   /**
    * The label on the button.
    *
    */

   private String _strLabel;

   /**
    * Constructs a circular button with no label.
    *
    */

   public CircularButton()
   {
      this("");
   }

   /**
    * Constructs a circular button with the specified label.
    *
    */

   public CircularButton(String strLabel)
   {
      enableEvents(AWTEvent.MOUSE_EVENT_MASK);
      enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
      enableEvents(AWTEvent.FOCUS_EVENT_MASK);

      _strLabel = strLabel;
   }

   /**
    * Gets the label.
    *
    */

   public String getLabel()
   {
      return _strLabel;
   }
 
   /**
    * Sets the label.
    *
    */

   public void setLabel(String strLabel)
   {
      _strLabel = strLabel;

      invalidate();

      repaint();
   }
 
   /**
    * Is the button pressed?
    *
    */

   private boolean _boolPressed = false;

   /**
    * Does the button have the input focus?
    *
    */

   private boolean _boolFocus = false;

   /**
    * Paint the circular button.
    *
    */

   public void paint(Graphics g)
   {
      Dimension dim = getSize();

      int n = (dim.width < dim.height ? dim.width : dim.height) - 1;
     
      // draw the interior

      if(_boolPressed)
      {
         g.setColor(getBackground().darker().darker());
      }
      else
      {
         g.setColor(getBackground());
      }

      g.fillArc(6, 6, n - 12, n - 12, 0, 360);
     
      // draw the perimeter

      g.setColor(getBackground().darker().darker().darker().darker());

      g.drawArc(6, 6, n - 12, n - 12, 0, 360);
     
      // draw the ring

      g.drawArc(0, 0, n, n, 0, 360);

      // fill the ring

      if (_boolFocus == true)
      {
         g.drawArc(1, 1, n - 2, n - 2, 0, 360);
         g.drawArc(2, 2, n - 4, n - 4, 0, 360);
         g.drawArc(3, 3, n - 6, n - 6, 0, 360);
     
         g.drawArc(0, 0, n - 1, n - 1, 0, 360);
         g.drawArc(1, 1, n - 1, n - 1, 0, 360);

         g.drawArc(1, 1, n - 3, n - 3, 0, 360);
         g.drawArc(2, 2, n - 3, n - 3, 0, 360);

         g.drawArc(2, 2, n - 5, n - 5, 0, 360);
         g.drawArc(3, 3, n - 5, n - 5, 0, 360);
      }

      // draw the label

      Font font = getFont();

      if (font != null)
      {
         FontMetrics fontmetrics = getFontMetrics(font);

         g.setColor(getForeground());

         g.drawString(_strLabel,
                      n/2 - fontmetrics.stringWidth(_strLabel)/2,
                      n/2 + fontmetrics.getMaxDescent());
      }
   }
 
   /**
    * The circular button's minimum size.
    *
    */

   private static Dimension _dimMinimumSize = new Dimension(100, 100);

   /**
    * Gets the minimum size.
    *
    */

   public Dimension getMinimumSize()
   {
      return new Dimension(_dimMinimumSize);
   }

   /**
    * Gets the preferred size (based on the label).
    *
    */

   public Dimension getPreferredSize()
   {
      Font font = getFont();

      if (font == null)
      {
         return new Dimension(_dimMinimumSize);
      }
      else
      {
         FontMetrics fontmetrics = getFontMetrics(font);

         int n = Math.max(fontmetrics.stringWidth(_strLabel) + 35,
                          fontmetrics.getHeight() + 35);

         return new Dimension(n, n);
      }
   }
 
   /**
    * The chain of action listeners.
    *
    */

   private ActionListener _al = null;

   /**
    * Adds an action listener.
    *
    */

   public void addActionListener(ActionListener al)
   {
       _al = AWTEventMulticaster.add(_al, al);
   }
 
   /**
    * Removes an action listener.
    *
    */

   public void removeActionListener(ActionListener al)
   {
       _al = AWTEventMulticaster.remove(_al, al);
   }

   /**
    * Determines whether or not the circular button contains
    * the point and the specified coordinates.
    */

   public boolean contains(int x, int y)
   {
      Dimension dim = getSize();

      int nX = dim.width/2;
      int nY = dim.height/2;

      return ((nX-x)*(nX-x)+(nY-y)*(nY-y)) <= (nX*nY);
   }
   
   /**
    * The currently active button.
    *
    */

   private Component _component = null;

   /**
    * Process focus events.
    *
    */

   public void processFocusEvent(FocusEvent e)
   {
      switch (e.getID())
      {
         case FocusEvent.FOCUS_GAINED:

            if (_boolFocus == false)
            {
               _boolFocus = true;

               repaint();
            }

            break;

         case FocusEvent.FOCUS_LOST:

            if (_boolFocus == true)
            {
               _boolFocus = false;

               repaint();
            }

            break;
      }

      super.processFocusEvent(e);
   }

   /**
    * Process mouse events.
    *
    */

   public void processMouseEvent(MouseEvent e)
   {
      switch (e.getID())
      {
         case MouseEvent.MOUSE_PRESSED:

            requestFocus();

            _component = e.getComponent();

            _boolPressed = true;

            repaint();

            break;

         case MouseEvent.MOUSE_RELEASED:

            _component = null;

            if (_boolPressed == true)
            {
               if (_al != null)
               {
                  _al.actionPerformed
                     (
                        new ActionEvent
                           (
                              this,
                              ActionEvent.ACTION_PERFORMED,
                              _strLabel,
                              e.getModifiers()
                           )
                     );
               }

               _boolPressed = false;
               
               repaint();
            }

            break;

         case MouseEvent.MOUSE_ENTERED:
           
            if (_component == e.getComponent() && _boolPressed == false)
            {
               _boolPressed = true;

               repaint();
            }

            break;

         case MouseEvent.MOUSE_EXITED:

            if (_boolPressed == true)
            {
               _boolPressed = false;

               repaint();
            }

            break;
      }

      super.processMouseEvent(e);
   }

   /**
    * Process mouse motion events.
    *
    */

   public void processMouseMotionEvent(MouseEvent e)
   {
      switch (e.getID())
      {
         case MouseEvent.MOUSE_DRAGGED:

            if (_component == e.getComponent() &&
                !contains(e.getX(), e.getY()) &&
                _boolPressed == true)
            {
               _boolPressed = false;

               repaint();
            }
            else if (_component == e.getComponent() &&
                     contains(e.getX(), e.getY()) &&
                     _boolPressed == false)
            {
               _boolPressed = true;

               repaint();
            }

            break;
      }

      super.processMouseMotionEvent(e);
   }
}

Hereda de un Componente en vez de un boton, se tiene que currar mas movidillas pero queda mejor.

Salu2o3
5  Programación / Java / Re: Java en: 27 Noviembre 2005, 01:46 am
Bueno, me ha resultado curiosa la idea y he encontrado esto:

Código:
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class RoundButton extends JButton {//Somos un boton :D
  public RoundButton(String label) {
super(label);   

// These statements enlarge the button so that it
// becomes a circle rather than an oval.
Dimension size = getPreferredSize();
size.width = size.height = Math.max(size.width,
  size.height);
setPreferredSize(size);

// This call causes the JButton not to paint
   // the background.
// This allows us to paint a round background.
setContentAreaFilled(false);
  }

// Paint the round background and label.
  protected void paintComponent(Graphics g) {
if (getModel().isArmed()) {
// You might want to make the highlight color
   // a property of the RoundButton class.
  g.setColor(Color.lightGray);
} else {
  g.setColor(getBackground());
}
g.fillOval(0, 0, getSize().width-1,
  getSize().height-1);

// This call will paint the label and the
   // focus rectangle.
super.paintComponent(g);
  }

// Paint the border of the button using a simple stroke.
  protected void paintBorder(Graphics g) {
g.setColor(getForeground());
g.drawOval(0, 0, getSize().width-1,
  getSize().height-1);
  }

// Hit detection.
  Shape shape;
  public boolean contains(int x, int y) {
// If the button has changed size,
   // make a new shape object.
if (shape == null ||
  !shape.getBounds().equals(getBounds())) {
  shape = new Ellipse2D.Float(0, 0,
getWidth(), getHeight());
}
return shape.contains(x, y);
  }

// Test routine.
  public static void main(String[] args) {
// Create a button with the label "Jackpot".
JButton button = new RoundButton("Jackpot");
button.setBackground(Color.green);

// Create a frame in which to show the button.
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.yellow);
frame.getContentPane().add(button);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(150, 150);
frame.setVisible(true);
  }
}

Es un poco cutre pero los colores que son bastante pobres...
Se ve bastante feo... pero bueno es un boton redondo.
Me parece wapa la idea de crear un nuevo boton :D

Salu2o3
6  Programación / Java / Re: Imprimir en Java???? en: 17 Noviembre 2005, 10:19 am
Aqui tienes todo lo que necesitas:

http://www.javaworld.com/javaworld/jw-10-2000/jw-1020-print.html

sale todo también bien especificado en la API de java
 Salu2
7  Programación / Java / Re: sockets + java? en: 12 Octubre 2005, 00:06 am
No se si entiendo muy bien la primera parte ... mensajes a muchos clientes supongo que será un servidor que pueda dar servicio a varios a la vez... Pos para eso pues creas un thread distinto para cada conexión nueva que te creen al puerto que tienes abierto.

Pues la diferencia entre los streams es mas o menos la manera que tiene de leer, o de trabajar por ejemplo el BufferedOutputStream -> no escribe hasta que se llena un buffer de un tamaño concreto... Pero cada stream es distinto eso lo mejor que puedes hacer es ir a la API de Java que es una gozada y leerte un poquillo todas esas movidillas.

Salu2o3
8  Programación / Java / Re: Problema al instalar Java 2 Runtime Enviorenment 1.5.0 02 en: 5 Junio 2005, 01:14 am
Desconecta internet cuando te vayas a conectar suelta el modem, cable-modem,  o cable de red :P

Salu2o3
9  Programación / Java / Re: Error al Compilar en Java en: 5 Junio 2005, 01:13 am
Buenas:

El error en ppio no es del path ni nada de eso... tienes todo bien puesto.
El problema es que no te deja escribir (crear ese fichero :S ), mira a ver escribiendo la salida en otro fichero (C:/misprogramas...) q tengan una direccion más corta... (No sería la primera vez que veo algo así...) Luego otra cosa... LA JDK 1.1.6!!!!!! ¿Cuantos años tiene esa máquina virtual?... instala por dios como mínimo la JDK 1.4 en serio nunca he visto algo así de antiguo... esa puede ser tambien origen de problema ;).

Pos eso si con esto no es posteas vale????

Salu2o3
10  Programación / Java / Re: Leer cabezeras ssl con java en: 22 Mayo 2005, 01:43 am
Espero que t sirva:

http://www.vonnieda.org/SSLv3/


Salu2o3
Páginas: [1] 2 3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines