Вы находитесь на странице: 1из 40

HOWTO Pruebas Multicast y Unicast

En primer lugar se debe armar una topologa, sobre la cual haremos nuestras pruebas, en nuestro caso usamos dos enrutadores linux y dos switches provistos por empresas de servicio de internet. Nuestra topologa esta formada por: Maquina(servidor) Samsung, con un disco duro de 500 GB, multiprocesador(4), Intel(R ) Core(TM) i5-2310M CPU @ 2.5GHz, con 3G de RAM Sistema Operativo: Debian 3.5.1 amd64. 2 maquinas(routers) Toshiba, con un disco duro de 320 GB, multiprocesador(4), Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz, con 6G de RAM Sistema Operativo: Debian 2.6.32-5 amd64. Las maquinas del centro de computo de nuestra facultad sirvieron como clientes.

Para nuestro caso, haremos uso de la herramienta VLC media player, que es un reproductor multimedia de cdigo abierto desarrollado por el proyecto VideoLan. Es un programa multiplataforma disponible para muchos sistemas operativos. VLC es un reproductor de audio y video capaz de reproducir muchos codecs y formatos de de audio y video, adems de capacidad de streaming. Procedemos a instalar VLC en cada una de las maquinas a utilizar. Lo podemos hacer con la siguiente linea de cdigo: sudo apt-get install vlc. Lo que deseamos hacer, es obtener conclusiones sobre los diferentes mtodos de transmisin, para ello necesitamos medir el flujo de datos que entran y salen por cada una de las interfaces de las maquinas, routers y por supuesto del servidor, para ello aremos uso de

una herramienta llamada MRTG. Asi que procedemos a instalar MRTG en cada una de las maquinas de la siguiente manera: sudo apt-get -y install mrtg mrtg-contrib mrtgutils Para que MRTG pueda correr sin ningn problema, necesitamos tener instalado apache, en caso de no tenerlo, lo instalamos de igual forma: sudo apt-get install apache2 Para poder actualizar las graficas de trasmisin en el tiempo que nosotros deseemos, sera necesario instalar RRDTOOL, el cual es un programa que nos permite capturar las grficas cada cierto tiempo (el que nosotros deseemos). Y lo hacemos de la misma manera: apt-get -y install rrdtool librrds-perl Ahora procedemos a instalar PIMD. PIMD es un programas que nos ayudara a enrutar paquetes multicast, para instalarlo, podemos hacerlo desde el Gestor de Paquetes Synaptic, para ello, vamos a Sistema Administracin Gestor de Paquetes Synaptic, luego ahi buscamos pimd y seleccionamos las dos opciones y por ultimo click en aplicar

Ahora que ya tenemos instaladas las herramientas a utilizar, procedemos a armar nuestra topologa y a configurar cada uno de los programas instalados. Configurar MRTG Para poder generar grficas en intervalos menores a 5 minutos se deben hacer algunas configuraciones, y decirle a MRTG que genere los datos y que estos sean ocupados por RRDTOOL para generar las grficas. Para ello se debe modificar el archivo de configuracin indicando entre otras cosas el directorio donde se guardaran los datos (WorkDir), el idioma, y el intervalo (Interval) en el cual queremos que los datos se estn actualizando. Tambin se debe indicar la configuracin para cada interfaz de red que queramos leer (mrtg creara una pagina html para cada interfaz, es por ello que se indica aqu el encabezado de la pagina, el titulo, la leyenda del grfico, etc). nano /etc/mrtg.cfg WorkDir: /var/www/mrtg Options[_]: bits,growright WriteExpires: Yes Logformat: rrdtool Language: spanish Interval: 0:01 Target[eth0]: `/usr/bin/mrtg-ip-acct eth0` MaxBytes1[eth0]: 1250000 MaxBytes2[eth0]: 1250000 Title[eth0]: Analisis del trafico total en eth0 YLegend[eth0]: Trafico PageTop[eth0]: <h1> Analisis del trafico total en eth0 </h1><br/> Para agregar mas interfaces se sigue el mismo procedimiento que se hace aqu cambiando eth0 por el nombre de la interfaz eth1, eth2, eth3, etc. Luego de configurar el mrtg, se debe correr de la siguiente manera: env LANG=C /usb/bin/mrtg /etc/mrtg.cfg Ahora mrtg ha creado en /var/www/mrtg los archivos html correspondientes a cada interfaz que configuramos eth0.html, eth1.html, etc tambien ha generado los archivos eth0.rrd, eth1.rrd, etc. Ahora solo falta modificar los archivos .rrd que ha creado mrtg y cambiarle el campo step para que puedan generar datos cada segundo (por defecto lo hacen cada 300 segundos) para lo cual debemos hacer lo siguiente: cd /var/www/mrtg Convertir los archivos .rrd a .txt para poder ser modificados, esto creara un archivo xml en el cual podremos modificar el campo step y ponerlo a 1 en lugar de 300. <step>1<step/>

rrdtool dump eth0.rrd convertido.txt nano convertido.txt Ahora se debe volver a convertir el archivo .txt a un archivo .rrd, pero antes debe eliminarse el archivo .rrd que ya no queremos: rm eth0.rrd rrdtool restore convertido.txt eth0.rrd Ahora todo esta listo para que se puedan generar los grficos cada segundo, para ellos debemos ejecutar el mrtg cada segundo para que genere los datos, y tambin debemos crear los grficos cada segundo por medio de rrdtool. Para hacer esto se puede crear un pequeo programa en C que ejecute cada segundo el mrtg y el script para generar los grficos, o tambin agregarlos al crontab. Script para generar los grficos. #!/bin/bash echo "Grafico de eth0" cd /var/www/mrtg rrdtool graph eth0-day.png -s -5min -e now -S 1 -v 'Trafico (Bits por Segundo)' -w 588 -h 324 DEF:in=eth0.rrd:ds0:AVERAGE DEF:out=eth0.rrd:ds1:AVERAGE CDEF:in_bits=in,8,* CDEF:out_bits=out,8,* AREA:in_bits#00FF00 LINE1:out_bits#0000FF \ COMMENT:" Hora\: `date +%H`\:`date +%M`\:`date +%S` \n" \ COMMENT:" Maximo Promedio Actual \n" \ GPRINT:in_bits:MAX:'%4.2lf %sb/s' \ GPRINT:in_bits:AVERAGE:"%4.2lf %Sb/s" \ GPRINT:in_bits:LAST:"%4.2lf %Sb/s \n" \ GPRINT:out_bits:MAX:'%4.2lf %sb/s' \ GPRINT:out_bits:AVERAGE:"%4.2lf %Sb/s" \ GPRINT:out_bits:LAST:"%4.2lf %Sb/s \n" \ El script anterior genera un grfico para la interfaz eth0 por medio de rrdtool graph, indicndole el nombre de la imagen a generar (eth0-day.png), el intervalo de tiempo desde donde queremos que comience la grfica (-s 5min) hasta donde queremos que termine (-e now), en este caso le estamos diciendo que comience 5 minutos en el pasado y llegue hasta el momento actual, si queremos la grfica de todo un da quedara as: -s 24h -e now. Tambin le indicamos el ancho y alto de la imagen en: -w 588 -h 324. MRTG guarda los datos en las variables ds0 y ds1 para entradas y salidas de cada interfaz respectivamente, por ello guardamos en las variables in y out los valores obtenidos de las variables ds0 y ds1 respectivamente, y luego graficamos con estos valores, las entradas se grafican con AREA por lo cual el flujo de entrada no es una linea, si no un area repintada de color verde (00ff00) y las salidas las graficamos con LINE1 por lo cual el flujo de salida es una linea de color azul(0000ff). Para las dems interfaces se sigue el mismo procedimiento, agregndolas al script.

Ahora solo queda crear el programa en C que llame a estos script y los ejecute, el cual quedara de la siguiente manera, con nombre graficarCron: #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(){ int cont=0; while(1==1){ cont++; printf("%d **************************************************\n",cont); printf("Se generan los datos\n"); system("env LANG=C /usr/bin/mrtg /etc/mrtg.cfg"); printf("Se grafican los datos con RRDT GRAPH\n"); system("./graficar"); sleep(1); } return 0; } Realizacion de las pruebas....

UNICAST
Ahora armamos nuestra topologia, detenemos el network-manager, procedemos a colocar las ip en las interfaces correspondientes, ejecutamos los programas instalados... Servidor: root@root:~# /etc/init.d/network-manager stop root@root:~#ifconfig eth0 192.168.1.1/24 up Ejecutamos el programa que creamos graficarCron root@root:~#./graficarCron Las graficas se podran ver en el navegador, colocaando http://localhost/mrtg/eth0 Ahora corremos el VLC, vamos a la opcin Medio Emitir, luego en aadir seleccionamos el archivo que deseamos transmitir , seleccionamos emitir, luego en la siguiente ventana damos clic en siguiente. Ahora donde dice Archivo seleccionamos RTP/MPEG TRANSPORT STREAM, y luego aadir, luego colocarnos la direccin donde queremos emitir y seleccionamos un puerto, clic en siguiente y activamos los anuncios SAP, y por ultimo clic en emitir.

Mas adelante observaremos como cambian las graficas a la hora de trasmitir. ROUTER A: root@root:~# /etc/init.d/network-manager stop Lo configuramos como router con la siguente linea, ponemos un 1 en lugar del 0 y guardamos root@root:~# nano /proc/sys/net/ipv4/conf/all/forwarding Este router tiene tres enlaces, por lo tanto llevara 2 adaptadores de red y el puerto que ya traen las maquinas. En nuestro caso, cada interfaz recibe el nombre de eth0, eth1 y eth2, debemos tener cuidado al momento de asignar las ip, ya que una confusin, generara errores que llevara horas encontrarlos. En la eth0 estamos conectados al servidor 192.168.1.2 En la eth1 estamos conectados al router B 192.168.5.2 En la eth2 estamos conectados al switch 192.168.3.2 root@root:~#ifconfig eth0 192.168.1.2/24 up root@root:~#ifconfig eth1 192.168.5.2/24 up root@root:~#ifconfig eth2 192.168.3.2/24 up Agregamos una ruta para llegar a la otra red root@root:~#route add -net 192.168.7.0/24 gw 192.168.5.4 Ejecutamos el programa que creamos graficarCron. Las grficas de eth0 se podrn ver en el navegador, colocando http://localhost/mrtg/eth0, y si queremos ver las de las otras interfaces solo cambiamos eth0 por la interfaz que queremos observar. root@root:~#./graficarCron ROUTER B: root@root:~# /etc/init.d/network-manager stop root@root:~# nano /proc/sys/net/ipv4/conf/all/forwarding root@root:~#ifconfig eth0 192.168.5.4/24 up root@root:~#ifconfig eth1 192.168.7.2/24 up root@root:~#route add -net 192.168.1.0/24 gw 192.168.5.2 root@root:~#route add -net 192.168.3.0/24 gw 192.168.5.2 root@root:~#./graficarCron Clientes: root@root:~# /etc/init.d/network-manager stop

root@root:~#ifconfig eth0 192.168.x.x/24 up root@root:~#./graficarCron Las X representan la red y el host que configure, (esto es igual para todos los clientes). Ahora ejecutamos el VLC para cada cliente de la siguiente forma: Medio Abrir Volcado de Red, colocamos nuestra direccion y el puerto por donde esta transmitiendo el servidor, y por ultimo clic en reproducir.

MULTICAST
Servidor: root@root:~# /etc/init.d/network-manager stop root@root:~#ifconfig eth0 192.168.1.1/24 up Activamos las opciones multicast en la interfaz por donde se emitiran datos, con la siguiente linea de codigo: root@root:~#ifconfig eth0 allmulti root@root:~#./graficarCron Ahora corremos el VLC, vamos a la opcin Medio Emitir, luego en aadir seleccionamos el archivo que deseamos transmitir , seleccionamos emitir, luego en la siguiente ventana damos clic en siguiente. Ahora donde dice Archivo seleccionamos RTP/MPEG TRANSPORT STREAM, y luego aadir, luego colocarnos una direccin multicast 239.100.100.100 y seleccionamos un puerto, clic en siguiente y activamos los anuncios SAP, y por ultimo clic en emitir. ROUTER A: root@root:~# /etc/init.d/network-manager stop root@root:~# nano /proc/sys/net/ipv4/conf/all/forwarding root@root:~#ifconfig eth0 192.168.1.2/24 up root@root:~#ifconfig eth1 192.168.5.2/24 up root@root:~#ifconfig eth2 192.168.3.2/24 up Activamos el multicasta para cada interfaz root@root:~#ifconfig eth0 allmulti root@root:~#ifconfig eth1 allmulti root@root:~#ifconfig eth2 allmulti root@root:~#route add -net 192.168.7.0/24 gw 192.168.5.4 Activamos el pimd con la siguiente linea root@root:~#/etc/init.d/pimd start

root@root:~#./graficarCron

ROUTER B: Ejecute los siguientes comandos para la configuracion. root@root:~# /etc/init.d/network-manager stop root@root:~# nano /proc/sys/net/ipv4/conf/all/forwarding root@root:~#ifconfig eth0 192.168.5.4/24 up root@root:~#ifconfig eth1 192.168.7.2/24 up root@root:~#ifconfig eth0 allmulti root@root:~#ifconfig eth1 allmulti root@root:~#route add -net 192.168.1.0/24 gw 192.168.5.2 root@root:~#route add -net 192.168.3.0/24 gw 192.168.5.2 root@root:~#/etc/init.d/pimd start root@root:~#./graficarCron Clientes: Ejecute las siguiente lineas de codigo en la terminal para la configuracion de cada cliente root@root:~# /etc/init.d/network-manager stop root@root:~#ifconfig eth0 192.168.x.x/24 up root@root:~#ifconfig eth0 allmulti root@root:~#./graficarCron Las X representan la red y el host que configure, (esto es igual para todos los clientes). Ahora ejecutamos el VLC para cada cliente de la siguiente forma: Medio Abrir Volcado de Red, colocamos la direccion multicast a la que el servidor esta trasmitiendo y el puerto por donde se esta transmitiendo.

ANALISIS
Observaremos como cambian las estadisticas de CPU y RAM del serividor cuando transmite multicast

Ahora el servidor trasmitiendo Unicast. Iremos mostrando una grafica por cada cliente agregado a la trasmicion. Antes de comenzar a trasmitir las estadiscas estaban asi:

Cliente 1:

Cliente 2:

Cliente 3:

Ahora veamos veamos las estadisticas de CPU y RAM del router A trasmitiendo multicast

Ahora iremos conectando cliente por clente en transimicon unicast al router A Cliente 1:

Cliente 2:

Cliente 3:

En cuanto al servidor, cuando se hace una trasmisin unicast, el consumo de memoria y cpu va aumentando conforme se van agregando los clientes; por el contrario, al hacer una trasmisin multicas, el servidor no varia de forma significativa en cuanto al uso de la cpu y memoria. En el caso del router, la trasmisin unicast tiene el mismo efecto que en el servidor; por otra parte, la trasmisin multicast, tambin hace que vaya aumentando el consumo de RAM y CPU, y esto es debido, a que en el router junto con los programas instalados y configurados en este documento, se encargan de sacar copias de los datos que le llegan. Por ejemplo, el servidor enva solamente un video al router, y de este salen tantas copias como clientes suscritos a ese grupo multicast. Ahora veamos los resultados del servidor en cuando a la taza de trasferencia

La trasmisin multicast se ve reflejada desde las 15:30 hasta las 16:40, luego comienza una trasmisin unicast, podemos observar claramente en la grfica, como aumenta la tasa de trasferencia conforme se van agregando clientes, (vemos 4 picos, eran 4 clientes), y as como la grfica aumenta, al ir aumentado clientes, tambin disminuye al ir quitando cliente por cliente. La grafica se dispara en la trasmisin unicicast, que comienza a las 16:50.

Anycast
Por definicin, el direccionamiento anycast asigna una direccin unicast a multiples interfaces, host o sercidores. En otras palabras, duplica la IP para configurar distintos servicios. Es un riesto y frecuentemente rompe la comunicacin cuando se usa el mismo enlace fsico en la red. No debera utilizarse sin protocolos de balanceo de carga sobre una red. Para implementar este mtodo, utilizaremos las siguientes subredes:

10.0.0.0/16

10.0.0.0/24

10.0.0.1 10.0.0.2 10.0.0.3 10.0.1.1 10.0.1.2 10.0.2.1 10.0.2.2

10.0.1.0/24

10.0.2.0/24

Se asignarn segn el diagrama presentado a continuacin:

Configurar servidor A Identificado como root, asigne una direccin ip a la interfaz eth0 # ifconfig eth0 10.0.1.1/24 up Crear una interfaz virtual a partir de lo. Agruegue luego la direccin ip con su mscara correspondiente. # ifconfig lo:0 192.168.0.1 netmask 255.255.255.255 up Verifique la configuracin anterior con # ifconfig
Que deber mostrar los cambios:

eth0 Link encap:Ethernet HWaddr 00:30:48:80:AF:9B inet addr:10.0.1.1 Bcast:10.0.1.255 Mask:255.255.255.0 inet6 addr: fe80::230:48ff:fe80:af9b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:33 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:248 (248.0 b) TX bytes:7307 (7.1 KiB) lo:0 Link encap:Local Loopback inet addr:192.168.0.1 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:16436 Metric:1 Ahora es necesario modificar el archivo named.conf, a travs de la terminal. Ubicandose en /etc/bind/named.conf escriba lo siguiente que configurar el servicio para que funciona a travs del puerto 53 con la direccin 192.168.0.1.

// named.conf Servidor A options { version "cualquiera"; server-id "A"; listen-on port 53 { 192.168.0.1;}; directory "/var/named"; allow-query { any; }; recursion yes; hostname "A"; }; logging { channel my_syslog { syslog daemon; severity info; }; channel named_log { file "logs/named.log" versions 5 size 1m; severity info; print-category yes; print-severity yes; print-time yes; }; channel query_log { file "logs/query.log" versions 5 size 1m; severity info; print-category yes; print-severity yes; print-time yes; }; category default { named_log; }; category xfer-out { my_syslog; named_log; }; category queries { query_log; }; }; zone "." IN {

type hint; file "named.ca"; }; Configurar servidor B Identificado como root, asigne una direccin ip a la interfaz eth0 # ifconfig eth0 10.0.2.1/24 up Crear una interfaz virtual a partir de lo. Agruegue luego la direccin ip con su mscara correspondiente. # ifconfig lo:0 192.168.0.1 netmask 255.255.255.255 up Verifique la configuracin anterior con # ifconfig Que deber mostrar los cambios: eth0 Link encap:Ethernet HWaddr 00:30:48:80:AF:9B inet addr:10.0.2.1 Bcast:10.0.1.255 Mask:255.255.255.0 inet6 addr: fe80::230:48ff:fe80:af9b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:33 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:248 (248.0 b) TX bytes:7307 (7.1 KiB) lo:0 Link encap:Local Loopback inet addr:192.168.0.1 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:16436 Metric:1 Modificar el archivo named.conf, para el servidor B ubicndose en /etc/bind/named.conf // named.conf Servidor B options { version "cualquiera"; server-id "B"; listen-on port 53 { 192.168.0.1;}; directory "/var/named"; allow-query { any; }; recursion yes; hostname "B"; }; logging { channel my_syslog { syslog daemon; severity info; }; channel named_log { file "logs/named.log" versions 5 size 1m; severity info; print-category yes; print-severity yes; print-time yes; };

channel query_log { file "logs/query.log" versions 5 size 1m; severity info; print-category yes; print-severity yes; print-time yes; }; category default { named_log; }; category xfer-out { my_syslog; named_log; }; category queries { query_log; }; }; zone "." IN { type hint; file "named.ca"; }; Enrutador 1 Ejecute la lnea para detener el network manager , indicada al principio de este tutorial, para que su computador Linux sea habilitado para enrutar, vea en la seccin Antes de comenzar. Siguiendo, en la terminal escriba: # ifconfig eth0 10.0.1.2/24 up Ejecute ifconfig para verificar cambios. Posteriormente se agregar una ruta por defecto a para alcanzar a los DNS # route add net 192.168.0.1 gw 10.0.1.1 Para realizar la unin entre el enrutador y switch, necesita una interfaz USB LAN, conctela a un puerto, luego ejecute ifconfig a y le mostrar el nombre con que el equipo reconoce el nuevo dispositivo de red. Identificado como root: #ifconfig ethx up #ifconfig ethx 10.0.0.2/24 up Para ver las rutas existentes ejecute route n Enrutador 2 Ejecute la lnea para detener el network manager , indicada al principio de este tutorial, para que su computador Linux sea habilitado para enrutar, vea en la seccin Antes de comenzar. Siguiendo, en la terminal escriba: # ifconfig eth0 10.0.2.2/24 up Ejecute ifconfig para verificar cambios. Posteriormente se agregar una ruta por defecto a para alcanzar a los DNS # route add net 192.168.0.1 gw 10.0.2.1 Conecte una interfaz USB LAN,n ejecute ifconfig a y le mostrar el nombre con que el equipo reconoce el nuevo dispositivo de red. Identificado como root: #ifconfig ethx up #ifconfig ethx 10.0.0.3/24 up Para ver las rutas existentes ejecute route -n Configuracin del Cliente

en el equipo que ser cliente, por medio de la terminal, escriba la lnea gedit /etc/resolv.conf escriba el nombre de dominio, en la opcin nameserver escriba la direccin ip con la que se identifica: 192.168.0.1. agregue las rutas para alcanzar a los servidores. # ifconfig eth0 10.0.0.1/24 up Ejecute ifconfig para verificar cambios. Posteriormente se agregarn rutas por defecto al cliente, para alcanzar a los DNS # route add default gw 10.0.0.2 metric 5 # route add default gw 10.0.0.3 El comando dig (Domain Information Groper) permite realizar consultas a los servidores DNS. Slo sirve para Internet, ya que no mira en /etc/hosts (slo utiliza/etc/resolv.conf). Para probar los servidores, hacer lo siguiente: ; <<>> DiG 9.6.0-P1 <<>> @192.168.0.1 id.server txt chaos ; (1 server found) ;; global options: +cmd ;; Got answer: Query time: 22 msec ;; SERVER: 192.168.0.1#53(192.168.0.1) ;; WHEN: Sat May 02 13:20:19 2009 ;; MSG SIZE rcvd: 55

AGREGADOS.
Para los agregados decidimos programar un chat orientado a la conexin en java, es decir, por medio de unicast, el chat usa sockets para la comunicacin con un servidor, todos los miembros del chat envan mensajes al servidor y este lo redirige a los dems miembros, fue pensado con la idea de que permita la conversacin entre mltiples usuarios, el reconocimiento de cada usuario que se conecta y se desconecta. CHAT DE MULTIPLES USUARIOS POR MEDIO DE SESIONS UNICAST. CLASE PRINCIPAL /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package chattcp; /** * * @author alexander */ public class Principal extends javax.swing.JFrame { /**

* Creates new form Principal */ public Principal() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton2 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton2.setText("Abrir Ventana Servidor"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton1.setText("Abrir Ventana Cliente"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(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() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G, false) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: new Cliente().setVisible(true); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: new Servidor().setVisible(true); } /** * @param args the command line arguments */ public static void main(String args[]) { /* * Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Principal.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Principal.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Principal.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Principal.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Principal().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; // End of variables declaration } FORMULARIO SERVIDOR /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package chattcp; import java.net.ServerSocket; import java.net.Socket; import javax.swing.JOptionPane; /** * * @author alexander */ public class Servidor extends javax.swing.JFrame { MServidor servidor; int puerto; /** * Creates new form Servidor */ public Servidor() { initComponents();

} /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Cantarell", 1, 18)); // NOI18N jLabel1.setText("Servidor"); jLabel2.setText("Puerto"); jTextField1.setText("7878"); jButton1.setText("Abrir Puerto"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(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() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G, false) .addComponent(jLabel1) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(jLabel2) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(servidor == null){ puerto = Integer.parseInt(jTextField1.getText()); servidor = new MServidor(puerto, this); servidor.start(); } } /** * @param args the command line arguments */ public static void main(String args[]) { /* * Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break;

} } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Servidor.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Servidor.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Servidor.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Servidor.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Servidor().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JTextField jTextField1; // End of variables declaration } FORMULARIO CLIENTE /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package chattcp; import java.net.Socket; import javax.swing.DefaultListModel; import javax.swing.JOptionPane; /**

* * @author alexander */ public class Cliente extends javax.swing.JFrame { MCliente cliente; String alias; private DefaultListModel modeloLista = new DefaultListModel(); /** * Creates new form Cliente */ public Cliente() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jTextField3 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jTextField4 = new javax.swing.JTextField(); jScrollPane2 = new javax.swing.JScrollPane(); jList1 = new javax.swing.JList(); jButton2 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setFont(new java.awt.Font("Cantarell", 1, 18)); // NOI18N jLabel1.setText("Cliente"); jLabel2.setText("Servidor"); jLabel3.setText("Puerto");

jTextField2.setText("7878"); jButton1.setText("Conectar"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); jTextField3.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { jTextField3KeyPressed(evt); } }); jLabel4.setText("Alias"); jScrollPane2.setViewportView(jList1); jButton2.setText("Desconectar"); jButton2.setEnabled(false); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(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() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI NG) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addComponent(jLabel1) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignme nt.LEADING) .addComponent(jLabel2) .addComponent(jLabel4)) .addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignme nt.LEADING, false) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE) .addComponent(jTextField4)))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE ADING) .addGroup(layout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(jLabel3) .addGap(6, 6, 6) .addComponent(jTextField2)) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELAT ED) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELAT ED) .addComponent(jButton2) .addGap(0, 0, Short.MAX_VALUE)))) .addComponent(jScrollPane1) .addComponent(jTextField3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA SELINE) .addComponent(jLabel2) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA SELINE) .addComponent(jLabel4)

.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1) .addComponent(jButton2)) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jScrollPane2)) .addContainerGap()) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jList1.setModel(modeloLista); int puerto = Integer.parseInt(jTextField2.getText()); String ip = jTextField1.getText(); alias = jTextField4.getText(); try{ if(cliente == null){ cliente = new MCliente(this, alias,ip, puerto); cliente.start(); } jButton1.setEnabled(false); jButton2.setEnabled(true); }catch(Exception e){ JOptionPane.showMessageDialog(this,e.getMessage()); cliente = null; } } private void jTextField3KeyPressed(java.awt.event.KeyEvent evt) { // TODO add your handling code here: if(evt.getKeyCode()==10){ //JOptionPane.showMessageDialog(this, "ok"); cliente.enviarMensaje(jTextField3.getText()); jTextField3.setText(""); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if(cliente!=null){

cliente.enviarTrama(3, ""); cliente.interrupt(); } cliente = null; jButton1.setEnabled(true); jButton2.setEnabled(false); modeloLista.removeAllElements(); jTextArea1.setText(""); } public void mensajeRecibido(String mensaje){ jTextArea1.append(mensaje+"\n"); } public void nuevaPersona(String alias){ modeloLista.addElement(alias); } public void borrarPersona(int nPos){ modeloLista.remove(nPos); } /** * @param args the command line arguments */ public static void main(String args[]) { /* * Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Cliente.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Cliente.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Cliente.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Cliente.class.getName() ).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* * Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Cliente().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JList jList1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; // End of variables declaration }

CLASE MCLIENTE (Encargada de manejar las funciones del cliente) /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package chattcp;

import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.Socket; import java.nio.channels.WritableByteChannel; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTextArea; /** * * @author alexander */ public class MCliente extends Thread{ Socket s; Cliente ventana; String ip,alias; int puerto; public MCliente(Cliente ventana,String alias,String ip,int puerto){ this.ventana = ventana; this.ip = ip; this.puerto = puerto; this.alias = alias; s = null; } public void run(){ try{ s = new Socket(ip,puerto); JOptionPane.showMessageDialog(ventana,"Conexion exitosa"); DataInputStream dis = new DataInputStream(s.getInputStream()); enviarTrama(1,alias); while(true){ int codigo = dis.readInt(); String trama = dis.readUTF(); if(codigo==1){ ventana.nuevaPersona(trama); }else if(codigo==2){ ventana.mensajeRecibido(trama); }else if(codigo==3){ try{ int nPos = Integer.parseInt(trama); ventana.borrarPersona(nPos); }catch(Exception e2){ } } } }catch(Exception e){

JOptionPane.showMessageDialog(ventana,"No se ha podido establecer la conexion"+e.getMessage()); //throw new Exception("No se ha podido establecer la conexion"+e.getMessage()); } } public void enviarMensaje(String mensaje){ enviarTrama(2, mensaje); } public void enviarTrama(int codigo,String trama){ try{ DataOutputStream dos = new DataOutputStream(s.getOutputStream()); dos.writeInt(codigo); dos.writeUTF(trama); }catch(Exception e){ JOptionPane.showMessageDialog(ventana,"No se pudo enviar el mensaje"); } } } CLASE MSERVIDOR (Encargada de manejar las funciones del servidor) /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package chattcp; import java.net.ServerSocket; import java.net.Socket; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JOptionPane; /** * * @author alexander */ public class MServidor extends Thread{ private int puerto; private JFrame ventana; public MServidor(int puerto,JFrame ventana){ this.puerto = puerto; this.ventana = ventana; }

public void run(){ ServerSocket ss=null; try{ ss = new ServerSocket(puerto); JOptionPane.showMessageDialog(ventana,"Se ha conectado"); while(true){ Socket s = ss.accept(); ManejadorConexiones.getConexion().nuevaConexion(new Conexion(s)); } }catch(Exception e){ JOptionPane.showMessageDialog(ventana,"Error al abrir el puerto"+e.getMessage()); } try{ ss.close(); }catch(Exception e){ } } } /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package chattcp; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author alexander */ CLASE conexin (Establece la conexin en un hilo independiente) public class Conexion extends Thread{ Socket s; DataInputStream dis; DataOutputStream dos; private String alias;

public Conexion(Socket s) throws Exception{ this.s = s; dis = new DataInputStream(s.getInputStream()); dos = new DataOutputStream(s.getOutputStream()); start(); } public void run(){ while(true){ try { int codigo = dis.readInt(); String trama = dis.readUTF(); if(codigo==1){ alias = trama; ManejadorConexiones.getConexion().enviarTrama(codigo,trama); }else if(codigo==2){ trama = "<"+alias+"> "+trama; ManejadorConexiones.getConexion().enviarTrama(codigo,trama); }else if(codigo==3){ ManejadorConexiones.getConexion().desconectar(this); } } catch (IOException ex) { //Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex); } } } public String getAlias(){ return alias; } public void enviarTrama(int codigo,String mensaje){ try{ dos.writeInt(codigo); dos.writeUTF(mensaje); }catch(Exception e){ } } } CLASE ManejadorConexiones (Permite gestionar las conexiones con el servidor, guardandolas en un arraylist de conexiones) /* * To change this template, choose Tools | Templates

* and open the template in the editor. */ package chattcp; import java.net.Socket; import java.util.ArrayList; /** * * @author alexander */ public class ManejadorConexiones { private static ManejadorConexiones conexion = new ManejadorConexiones(); public static ManejadorConexiones getConexion(){ return conexion; } private ArrayList<Conexion> conexiones = new ArrayList<Conexion>(); public void enviarTrama(int codigo,String trama){ for(Conexion ms:conexiones){ ms.enviarTrama(codigo,trama); } } public void nuevaConexion(Conexion nuevo){ for(Conexion ms:conexiones){ nuevo.enviarTrama(1, ms.getAlias()); } conexiones.add(nuevo); } public void desconectar(Conexion eliminar){ int nPos=-1; for(int n=0;n<conexiones.size();n++){ if(conexiones.get(n) == eliminar){ nPos=n; } } if(nPos!=-1){ for(int n=0;n<conexiones.size();n++){ if(n!=nPos){ conexiones.get(n).enviarTrama(3,""+nPos); } } conexiones.remove(nPos); }

} public ManejadorConexiones(){ } } EJEMPLO DE ENVO DE ARCHIVOS EN JAVA. El cliente envia un archivo al servidor y este lo guarda en el directorio donde se encuentre ejecutandose. CLASE SERVIDOR. package archivos; import java.net.*; import java.io.*; class Servidor{ public static void main (String[] args){ ServerSocket servidor; Socket conexion; DataOutputStream salida; BufferedInputStream bis; BufferedOutputStream bos; byte[] receivedData; int in; String archivo; try{ servidor = new ServerSocket( 1234 ); while ( true ) { conexion = servidor.accept(); receivedData = new byte[1024]; bis = new BufferedInputStream(conexion.getInputStream()); DataInputStream dis=new DataInputStream(conexion.getInputStream()); //recibimos el nombre del fichero archivo = dis.readUTF(); archivo = archivo.substring(archivo.indexOf('/')+1,archivo.length()); bos = new BufferedOutputStream(new FileOutputStream(archivo));

while ((in = bis.read(receivedData)) != -1){ bos.write(receivedData,0,in); } bos.close(); dis.close(); } }catch (Exception e ) { System.err.println(e); } } } CLASE CLIENTE package archivos; /** * * @author Miguel Peinado * @author Timoteo Ponce */ import java.net.*; import java.io.*; class Cliente{ public static void main (String[] args){ DataInputStream entrada; BufferedInputStream bis; BufferedOutputStream bos; int in; byte[] arregloDeBytes; final String filename = "/home/alexander/juegoGoku.jar"; try{ final File archivoLocal = new File( filename ); //Se est probando dentro de la misma maquina Socket cliente = new Socket("127.0.0.1", 1234); bis = new BufferedInputStream(new FileInputStream(archivoLocal)); bos = new BufferedOutputStream(cliente.getOutputStream()); //enviamos el nombre del archivo DataOutputStream dos=new DataOutputStream(cliente.getOutputStream()); dos.writeUTF(archivoLocal.getName()); arregloDeBytes = new byte[8192]; while ((in = bis.read(arregloDeBytes)) != -1){ bos.write(arregloDeBytes,0,in); }

bis.close(); bos.close(); }catch ( Exception e ) { System.err.println(e); } } }

REFERENCIAS.
http://es.scribd.com/doc/43373910/Unicast http://zytrust.blogspot.com/2007/10/multicast.html http://www.see-my-ip.com/tutoriales/protocolos/ipv6_tipos_direccionamiento.php http://fermat.usach.cl/~msanchez/Multcast/ http://naysm.wordpress.com/2009/10/13/metodo-de-transmision/ http://netlinxinc.com/netlinx-blog/45/119.html http://www.forosdelweb.com/f45/transmitir-video-tiempo-real-320961/ http://es.scribd.com/doc/42018027/139/Con%EF%AC%81guring-Multicast-Routing-on-UNIXSystems http://wifihack.net/blog/2009/07/igmpv3-multicasting-linux-mrouter-with-xorp-how-to-on-ubuntu/ http://www.jukie.net/~bart/multicast/Linux-Mrouted-MiniHOWTO.html http://rolandopalermo.blogspot.com/2010/06/procesamiento-de-video-en-tiempo-real.html http://rolandopalermo.blogspot.com/2010/08/transmision-de-video-usando-sockets-en.html http://www.elrincondemartin.org/2012/06/rrdtool-primeros-pasos-parte-1.html http://eljamonyelvino.blogspot.com/2007/09/enchulame-el-grafiquito.html http://oss.oetiker.ch/mrtg/doc/mrtg-reference.en.html http://eljamonyelvino.blogspot.com/2007/09/implementando-rrdtool-con-mrtg-y-no.html http://oss.oetiker.ch/rrdtool/gallery/index.en.html http://aldarias.es/pacodebian/mrtg.html http://preguntaslinux.org/-howto-instalacion-de-mrtg-monitoreo-debian-t-3061.html http://oss.oetiker.ch/mrtg/doc/mrtg-unix-guide.en.html http://www.debianhelp.co.uk/apache2.htm http://es.wikihow.com/usar-VLC-para-transmitir-audio-y-video-en-varias-computadoras-en-unared-usando-Multicast http://www.cisco.com/en/US/tech/tk828/technologies_tech_note09186a0080094821.shtml http://www.linuxfocus.org/Castellano/January2001/article144.shtml#lfindex3 http://www.kuro5hin.org/story/2003/12/31/173152/86

Вам также может понравиться