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 4 5 6 7 8 9 10 11 12
11  Programación / Java / Re: [Sockets] Sirven en internet? en: 2 Diciembre 2011, 23:16 pm
Puse la ip que sale en es pagina, el chico al que le pedi que ejecutara el cliente me dijo lo siguiente:

"ahora si abrio algo­­ y dije hola­­"

No se si creerle, pero si es cierto algo anda mal en mi code, si es mentira quizas sea algo mas que haya que hacer.

12  Programación / Bases de Datos / Es verdad que mysql es orientado a objetos? en: 2 Diciembre 2011, 23:10 pm
Eso, un profesor habló conmigo y dijo que mysql era orientado a objetos, que se podian crear clases y que las columnas podian guardar objetos, estuve buscando info relacionada y solo encontre clases php que manejan mysql, ¿es esto cierto o es parte de la descabellada fantasía de mi profesor o es mi ineptitud la que no me permitió encontrar documentacion?

De antemano, gracias por sus respuestas
13  Programación / Java / Re: [Sockets] Sirven en internet? en: 2 Diciembre 2011, 22:27 pm
Olvide poner el main, aunque no hace mucho:

Código
  1.  
  2. public class Main {
  3.  
  4.    public static void main(String[] args) {
  5.  
  6.     //xserver();
  7.     //xclient();
  8.  
  9.    }
  10.  
  11. }
  12.  
  13.  

Para probarlo en localhost, primero se conecta como server, luego como client (sacando los respectivos comentarios) y en la linea 22 de XClient el primer argumento es "localhost", esta es mi duda, que debo poner en localhost, por que al hacer ipconfig, me salen un monton de numeros y el amigo que recibio el jar cliente ya no esta conectado Xd (la conexion aqui en mi instituto es ipv6, ¿sera por eso?  ojalá que no :-\)

Saludos!
14  Programación / Java / Re: [Opinión / Retroalimentación] ¿Clases Anónimas o Separadas? en: 2 Diciembre 2011, 22:03 pm
Pienso que una clase anónima no necesariamente se involucra con la gui, y tampoko necesariamente el codigo se desorganizará that is, my humble opinion, me expongo a un flame  ;D, saludos
15  Programación / PHP / [PHP + JSP] Es posible? en: 2 Diciembre 2011, 21:19 pm
Hola, estuve leyendo en un libro que se podía mezclar java con php, en el servidor tomcat, dejo el extracto del libro:

Introduccion:

Cita de: (2004) Php 5 And Mysql Bible

The relationship between PHP and Java has changed significantly
with each new release. Unsurprisingly, given the source code, PHP
initially had much more in common with C. PHP4 supported integration
of PHP and Java using a Java Servlet environment or, more experimentally,
directly into PHP. Finally, with the overhaul of the object
model in PHP5, there’s a distinctly Java feel to the PHP approach to
object oriented programming. Java users will find much of PHP5’s
new object model very familiar, though with important differences.
Given these changes, as PHP takes on a more Java-like cast, there are
two possibilities for which a discussion of PHP and Java might be
pertinent. You might need to work on a project that requires PHP and
Java or Java Server Pages (JSP) to work in tandem. Or you may be
approaching PHP from a Java background and want to know about
the similarities and differences in order to learn PHP faster. We will
deal with both needs in this chapter.
If you don’t have a need to use Java, or aren’t already


Expolicacion y ejemplo:

Cita de: (2004) Php 5 And Mysql Bible

Java Server Pages and PHP
PHP can fulfill many functions similarly to Java Server Pages (JSP). The JSP servlet engine
serves as a scripting language for use with Java, and, just as PHP, is often used in front end
applications.
Embedded HTML
PHP is more similar to JSP than Java itself in that you are allowed to write HTML directly
rather than using endless print statements. Unlike Java, but like JSP, variables can also be
referenced from within a block of HTML. A simple HTML page using JSP script might look
like this:
<%
String greeting = “Hello, world”;
%>
<HTML>
<HEAD>
<TITLE>Fun with JSP</TITLE>
</HEAD>
<BODY>
<H1><%= greeting %></H1>
</BODY>
</HTML>
Similarly, using PHP, you can write:
<?php
$greeting = “Hello, World”;
?>
<HTML>
<HEAD>
<TITLE>Fun with PHP</TITLE>
722 Part IV ✦ Connections
</HEAD>
<BODY>
<H1><?php echo $greeting ?></H1>
</BODY>
</HTML>
Pages can freely alternate between HTML and JSP, just as in using HTML and PHP.


De antemano, gracias por sus respuestas.

PD: Tengo el apache tomcat instalado, pero es la instalacion que viene por defecto, sinceramente no se por donde empezar, si alguien quiere el libro que me mande un mp y se lo mando por correo. 1083 paginas, esto de java+php empieza en la 719
16  Programación / Java / [Sockets] Sirven en internet? en: 2 Diciembre 2011, 21:07 pm
Hola, estuve viendo unos videotutoriales que me paso un amigo, el tipo se llama nikitus y enseña a crear una conexion con sockets, en el video muestra como hacer un pequeño xat, todo el codigo funka, pero me gustaria saber si es posible hacer que funke en internet, traté de poner mi direccion ip en el programa cliente y pasarselo a un amigo, pero no funciono, codeé en base al video, dos clases, un cliente y un server, en localhost corre bien, pero me gustaría saber, si es posible, que debo cambiarle para que funcione en internet, de antemano gracias.

Clase servidor:

Código
  1.  
  2. import java.net.ServerSocket;
  3. import java.net.Socket;
  4. import java.io.ObjectOutputStream;
  5. import java.io.IOException;
  6. import java.io.ObjectInputStream;
  7. import javax.swing.JOptionPane;
  8.  
  9. public class XServer {
  10.  
  11.  private ServerSocket ss;
  12. private Socket s;
  13. private ObjectOutputStream oos;
  14. private boolean isRunning=true;
  15. private ObjectInputStream ois;
  16. private volatile Command cmd=null;
  17.  
  18.  
  19.    XServer(){
  20.  
  21.          try{
  22.  
  23.     ss = new ServerSocket(9999);
  24.     s = ss.accept();
  25.     oos=new ObjectOutputStream(s.getOutputStream());
  26.     ois=new ObjectInputStream(s.getInputStream());
  27.  
  28.     }catch(IOException ioex){
  29.  
  30.      ioex.printStackTrace();
  31.  
  32.     }
  33.  
  34. this.sender();
  35. this.receiver();
  36. this.dealReceive();
  37. this.autoClose();
  38.  
  39.    }
  40.  
  41.    void sender(){
  42.  
  43. Thread t=new Thread(new Runnable(){
  44.  
  45.  public void run(){
  46.  
  47.   while(XServer.this.isRunning){
  48.  
  49.    int type=0;
  50.  
  51.    try{
  52.  
  53.  String msg=JOptionPane.showInputDialog("Mensaje para el Cliente");
  54.  
  55.   Command c=new Command();
  56.  
  57.   c.setMsg(msg);
  58.  
  59.   type=(msg.equalsIgnoreCase("Close"))? 0:1;
  60.  
  61.   c.setType(type);
  62.  
  63.   oos.writeObject(c);
  64.  
  65.  }catch(IOException ex) {
  66.  
  67.   ex.printStackTrace();
  68.  
  69.  }
  70.  
  71.    if(type==0){
  72.  
  73.     break;
  74.  
  75.    }
  76.  
  77.   }
  78.  
  79.  }
  80.  
  81. });
  82.  
  83. t.start();
  84.  
  85.    }
  86.  
  87.    void receiver(){
  88.  
  89.    Thread t=new Thread(new Runnable(){
  90.  
  91.     public void run(){
  92.  
  93.      while(XServer.this.isRunning){
  94.  
  95.        try{
  96.  
  97.      Thread.sleep(1000);
  98.  
  99.      Object aux=ois.readObject();
  100.  
  101.      if(aux!=null && aux instanceof Command){
  102.  
  103.        XServer.this.cmd = (Command) aux;
  104.  
  105.      }
  106.  
  107.     }catch(InterruptedException intex){
  108.  
  109.      intex.printStackTrace();
  110.  
  111.     }catch(IOException ioex){
  112.  
  113.      ioex.printStackTrace();
  114.  
  115.     }catch(ClassNotFoundException classex){
  116.  
  117.      classex.printStackTrace();
  118.  
  119.     }
  120.  
  121.      }
  122.  
  123.     }
  124.  
  125.    });
  126.  
  127.    t.start();
  128.  
  129.    }
  130.  
  131.    void dealReceive(){
  132.  
  133.     Thread t=new Thread(new Runnable(){
  134.  
  135.      public void run(){
  136.  
  137.       while(XServer.this.isRunning){
  138.  
  139.       try{
  140.  
  141.        Thread.sleep(1000);
  142.  
  143.        Command c=XServer.this.cmd;
  144.  
  145.        if(c.getType().equals("Message")){
  146.  
  147.         System.out.println(c.getMsg());
  148.  
  149.        }else if(c.getType().equals("Action") && c.getMsg().equals("Close")){
  150.  
  151.         XServer.this.isRunning=false;
  152.  
  153.        }
  154.  
  155.     }catch(InterruptedException intex){
  156.  
  157.      intex.printStackTrace();
  158.  
  159.     }catch(NullPointerException nullex){
  160.  
  161.     }finally{
  162.  
  163.       XServer.this.cmd=null;
  164.  
  165.     }
  166.  
  167.     }
  168.  
  169.      }
  170.  
  171.     });
  172.  
  173.     t.start();
  174.  
  175.    }
  176.  
  177.    void autoClose(){
  178.  
  179. Thread t=new Thread(new Runnable(){
  180.  
  181.  public void run(){
  182.  
  183.   while(true){
  184.  
  185.    try{
  186.  
  187.     Thread.sleep(200);
  188.  
  189.     if(!XServer.this.isRunning){
  190.  
  191.      XServer.this.ois.close();
  192.      XServer.this.oos.close();
  193.      XServer.this.s.close();
  194.  
  195.     }
  196.  
  197.    }catch(InterruptedException intex){
  198.  
  199.     intex.printStackTrace();
  200.  
  201.    }catch(IOException ioex){
  202.  
  203.     ioex.printStackTrace();
  204.  
  205.    }
  206.  
  207.   }
  208.  
  209.  }
  210.  
  211. });
  212.  
  213. t.start();
  214.  
  215. }
  216.  
  217. }
  218.  
  219.  
  220.  

Clase cliente:

Código
  1.  
  2. import java.net.Socket;
  3. import java.io.ObjectOutputStream;
  4. import java.io.IOException;
  5. import java.io.ObjectInputStream;
  6. import javax.swing.JOptionPane;
  7.  
  8. public class XClient {
  9.  
  10.  private Socket s;
  11. private ObjectOutputStream oos;
  12. private boolean isRunning=true;
  13. private ObjectInputStream ois;
  14. private volatile Command cmd=null;
  15.  
  16.  
  17.    XClient(){
  18.  
  19.               try{
  20.  
  21.     s=new Socket("10.5.4.124", 9999);
  22.     oos=new ObjectOutputStream(s.getOutputStream());
  23.     ois=new ObjectInputStream(s.getInputStream());
  24.  
  25.     }catch(IOException ioex){
  26.  
  27.      ioex.printStackTrace();
  28.  
  29.     }
  30.  
  31.               this.sender();
  32.               this.receiver();
  33.               this.dealReceive();
  34.               this.autoClose();
  35.  
  36.    }
  37.  
  38.    void receiver(){
  39.  
  40.    Thread t=new Thread(new Runnable(){
  41.  
  42.     public void run(){
  43.  
  44.      while(XClient.this.isRunning){
  45.  
  46.        try{
  47.  
  48.      Thread.sleep(1000);
  49.  
  50.      Object aux=ois.readObject();
  51.  
  52.      if(aux!=null && aux instanceof Command){
  53.  
  54.        XClient.this.cmd = (Command) aux;
  55.  
  56.      }
  57.  
  58.     }catch(InterruptedException intex){
  59.  
  60.      intex.printStackTrace();
  61.  
  62.     }catch(IOException ioex){
  63.  
  64.      ioex.printStackTrace();
  65.  
  66.     }catch(ClassNotFoundException classex){
  67.  
  68.      classex.printStackTrace();
  69.  
  70.     }
  71.  
  72.      }
  73.  
  74.     }
  75.  
  76.    });
  77.  
  78.    t.start();
  79.  
  80.    }
  81.  
  82.        void dealReceive(){
  83.  
  84.     Thread t=new Thread(new Runnable(){
  85.  
  86.      public void run(){
  87.  
  88.       while(XClient.this.isRunning){
  89.  
  90.       try{
  91.  
  92.        Thread.sleep(1000);
  93.  
  94.        Command c=XClient.this.cmd;
  95.  
  96.        if(c.getType().equals("Message")){
  97.  
  98.         System.out.println(c.getMsg());
  99.  
  100.        }else if(c.getType().equals("Action") && c.getMsg().equals("Close")){
  101.  
  102.         XClient.this.isRunning=false;
  103.  
  104.        }
  105.  
  106.     }catch(InterruptedException intex){
  107.  
  108.      intex.printStackTrace();
  109.  
  110.     }catch(NullPointerException nullex){
  111.  
  112.     }finally{
  113.  
  114.       XClient.this.cmd=null;
  115.  
  116.     }
  117.  
  118.     }
  119.  
  120.      }
  121.  
  122.     });
  123.  
  124.     t.start();
  125.  
  126.    }
  127.  
  128. void sender(){
  129.  
  130. Thread t=new Thread(new Runnable(){
  131.  
  132.  public void run(){
  133.  
  134.   while(XClient.this.isRunning){
  135.  
  136.    int type=0;
  137.  
  138.    try{
  139.  
  140.  String msg=JOptionPane.showInputDialog("Mensaje para el Server");
  141.  
  142.   Command c=new Command();
  143.  
  144.   c.setMsg(msg);
  145.  
  146.   type=(msg.equalsIgnoreCase("Close"))? 0:1;
  147.  
  148.   c.setType(type);
  149.  
  150.   oos.writeObject(c);
  151.  
  152.  }catch(IOException ex) {
  153.  
  154.   ex.printStackTrace();
  155.  
  156.  }
  157.  
  158.    if(type==0){
  159.  
  160.     break;
  161.  
  162.    }
  163.  
  164.   }
  165.  
  166.  }
  167.  
  168. });
  169.  
  170. t.start();
  171.  
  172.    }
  173.  
  174. void autoClose(){
  175.  
  176. Thread t=new Thread(new Runnable(){
  177.  
  178.  public void run(){
  179.  
  180.   while(true){
  181.  
  182.    try{
  183.  
  184.     Thread.sleep(200);
  185.  
  186.     if(!XClient.this.isRunning){
  187.  
  188.      XClient.this.ois.close();
  189.      XClient.this.oos.close();
  190.      XClient.this.s.close();
  191.  
  192.     }
  193.  
  194.    }catch(InterruptedException intex){
  195.  
  196.     intex.printStackTrace();
  197.  
  198.    }catch(IOException ioex){
  199.  
  200.     ioex.printStackTrace();
  201.  
  202.    }
  203.  
  204.   }
  205.  
  206.  }
  207.  
  208. });
  209.  
  210. t.start();
  211.  
  212. }
  213.  
  214. }
  215.  
  216.  

Se me olvidaba, para lo que quiero hacer despues de aprender a manipular sockets en internet creé una clase comando, que en el futuro me servirá para mandar solo strings con referencias a lo que se debe hacer y no mandar objetos pesados a traves de la conexion, esta es la clase:

Código
  1.  
  2. import java.io.Serializable;
  3.  
  4. public class Command implements Serializable{
  5.  
  6. private String[] types={"Action", "Message", "Dialog", "Input", "Warning", "Error"};
  7. private String[] actions={"Close"};
  8.  
  9. private String type="";
  10. private String msg="";
  11.  
  12.    Command(){
  13.  
  14.     this.type= types[1];
  15.  
  16.    }
  17.  
  18.    Command(String msg){
  19.  
  20.     this.type=this.types[0];
  21.     this.msg=msg;
  22.  
  23.    }
  24.  
  25.    Command(String msg, int type){
  26.  
  27.     this.type=this.types[type];
  28.     this.msg=msg;
  29.  
  30.    }
  31.  
  32. public String getMsg() {
  33.  return msg;
  34. }
  35.  
  36. void setDialog(String msg){
  37.  
  38.  this.msg=msg;
  39.  this.type=types[2];
  40.  
  41. }
  42.  
  43. void setInput(String msg){
  44.  
  45.  this.msg=msg;
  46.  this.type=types[3];
  47.  
  48. }
  49.  
  50. void setWarning(String msg){
  51.  
  52.  this.msg=msg;
  53.  this.type=types[4];
  54.  
  55. }
  56.  
  57. void setError(String msg){
  58.  
  59.  this.msg=msg;
  60.  this.type=types[5];
  61.  
  62. }
  63.  
  64. public void setMsg(String msg) {
  65.  this.msg = msg;
  66. }
  67.  
  68. public void setType(int i){
  69.  
  70.  this.type=this.types[i];
  71.  
  72. }
  73.  
  74. public String getType(){
  75.  
  76.  return this.type;
  77.  
  78. }
  79.  
  80.  
  81.  
  82. }
  83.  
  84.  
  85.  


Bueno, de antemano agradezco muchísimo vuestras respuestas, saludos
17  Programación / Java / Re: Creación de Sudokus en: 2 Diciembre 2011, 03:45 am
Re-Subido, siento la demora
18  Programación / Bases de Datos / Re: batch q ejecute un script de sql? en: 11 Noviembre 2011, 21:48 pm
Puedo aprovechar de preguntar si se puede para mysql y para oracle?  :D
19  Programación / Bases de Datos / [MYSQL] Otra forma de hacer esta consulta? en: 11 Noviembre 2011, 21:45 pm
Hola, tengo la siguiente base de datos en mysql:

Código
  1.  
  2. CREATE DATABASE IF NOT EXISTS verduleros;
  3.  
  4. DROP TABLE IF EXISTS ventas2;
  5.  
  6. CREATE TABLE ventas2(
  7.  
  8. idventa INT NOT NULL PRIMARY KEY,
  9. vendedor VARCHAR(255) NOT NULL,
  10. producto VARCHAR(255) NOT NULL,
  11. fecha DATE NOT NULL,
  12. kilos INT NOT NULL
  13.  
  14. )engine=innodb;
  15.  
  16.  


La consulta que quiero realizar segun el planteamiento es:

"Desplegar la suma de los kilos de cada producto que ha vendido cada vendedor"

Para ello pense en la siguiente consulta:

Código
  1. SELECT v.vendedor, v.producto,
  2. SUM(v.kilos)
  3. FROM ventas2 AS v
  4. WHERE v.kilos IN
  5. (SELECT kilos FROM ventas2 WHERE vendedor=v.vendedor AND
  6. producto=v.producto)
  7. GROUP BY vendedor
  8. ;
  9.  

El problema es que la base de datos es muy grande xD, probé la lógica de esta
consulta en una tabla pequeña y funciona, pero en la base de datos que nos entregó el profe esperé alrededor de unos 20 minutos y no me mostró nada,
lo intenté en reiteradas veces, probé a reiniciar el pc y nada, la base de datos es muy grande por lo tanto no puedo hacer esto con subconsultas (y, pensandolo, si la consulta por si sola se demora, hacer por cada fila una subconsulta es descabellado xD), se los agradecería enormemente si es posible hacer esto de otra forma.

Saludos!
20  Programación / Java / Re: arraylist character to arraylist String en: 1 Noviembre 2011, 03:40 am
Es un tipo especial de for, se llama for each, lo que hace es recorrer el arreglo completo

for(tipo_de_dato variable:arreglo){

//codigo

}

Donde variable en cada vuelta tomara un valor de arreglo, hasta llegar al último valor del arreglo, por cierto cualquier cosa a la que le concatenes "" (excepto objetos) se convierte en un String, ejemplo:

char variable='c';

String str=c+"";

String str2+=c;

char c='9';

int b=Integer.parseInt(c+"");

Saludos!
Páginas: 1 [2] 3 4 5 6 7 8 9 10 11 12
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines