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

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Por favor me pueden ayudar con esta practica UDP en Java en: 27 Octubre 2007, 18:25 pm
Pues eso, haber si alguien por favor seria tan amable de colaborarme con esta practica

http://www.zshare.net/download/4487693cad378a/

o decirme donde consigo informacion sobre sockets pero que este bien explicado como envio y recibo: desde un server y desde un cliente

gracias

ahh lo que he logrado hacer es simplemente paso de mensajes

Cliente
Código:
import java.net.*;
import java.io.*;

public class ClienteSaludoUDP{
 public static void main(String args[]){
 String mensaje;
 if(args.length==1){
   mensaje=args[0];
   DatagramSocket socket=null;
   try{
    byte[]buffer_salida=mensaje.getBytes();
    InetAddress destino = InetAddress.getByName("localhost");
    DatagramPacket datagrama = new DatagramPacket(buffer_salida,buffer_salida.length,destino,9000);
    socket = new DatagramSocket();
    socket.send(datagrama); 
   } catch(IOException e){
      e.printStackTrace();
      } finally {
        if(socket != null) socket.close();
        }
  }
  else{
     System.out.println("USo:ClienteSaludoUDP mensaje");
  }
 }
}   

Servidor
Código:
import java.net.*;
import java.io.*;

public class ServidorSaludoUDP
{
 public static void main(String args[])
 {
  try
    {
      DatagramSocket socket = new DatagramSocket(9000);
      byte[] buffer_entrada = new byte[255];
      byte[] datos;
      String mensaje;
      do
       {       
        DatagramPacket datagrama = new DatagramPacket(buffer_entrada,buffer_entrada.length);
        System.out.println("Servidor>))))))...");
        socket.receive(datagrama);
        System.out.println("Recibiendo Informacion: ");
        InetAddress hostDestino = datagrama.getAddress();
        int puertoDestino = datagrama.getPort();
        datos = datagrama.getData();
       

       
       
        mensaje = new String(datos,0,datos.length);
     


        System.out.println("Clente: "+hostDestino.getCanonicalHostName()+"|Puerto #"+puertoDestino+"|          Mensaje:"+mensaje.trim());
        for( int i=0; i < datagrama.getLength(); i++ )
        datos[i] = (byte)(' ');
        System.out.println("==============================================================");
      } while(true);
    }
   catch(IOException e)
   {e.printStackTrace();}
 }

}
:-[ :xD :D
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines