La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

Cliente Servidor.

Presentaciones similares


Presentación del tema: "Cliente Servidor."— Transcripción de la presentación:

1 Cliente Servidor

2

3

4

5 public class T extends Thread {
private Socket s; public T(Socket x){s=x;} public void run(){try{ //escuchar al cliente BR in=new BR(new ISR(s.getInputStream())); while(true){ String linea=in.readLine(); System.out.println(linea); if(linea.equals(“fin”)) break; } in.close(); s.close(); }catch(Exception e){ System.err.println(e.getMessage()); }} Nota. Las líneas de los clientes se mezclan en System.out

6 public class T extends Thread {
private Socket s; public T(Socket x){s=x;} public void run(){try{ //obtener dir simbólica del cliente String c=s.getInetAddress().getHostName(); BR in=new BR(new ISR(s.getInputStream())); while(true){ String linea=in.readLine(); System.out.println(c+”:”+linea); if(linea.equals(“fin”)) break; } a.close(); s.close(); }catch(Exception e){ System.err.println(e.getMessage()); }}

7 Un servidor de archivos: envía archivos a petición de clientes
2) Servidor recibe nombre de archivo 1) cliente solicita archivo 4) Servidor envía bytes 5) Cliente graba bytes 3) Leer bytes desde archivo Repetir 3,4,5 hasta que todo el archivo sea transmitido

8

9

10

11

12 //obtener segmentos de bytes y
//grabar en archivo local FileOutputStream a= new FileOutputStream(args[0]); InputStream in=s.getInputStream(); int N=1024,n=0; byte[]b=new byte[N]; while((n=in.read(b,0,N)>=0) a.write(b,0,n); a.close(); in.close(); s.close();

13 Broadcasting (Difusión) de mensajes
Hello Hello Hello Hello Hello Hello

14

15

16

17 Cliente Servidor


Descargar ppt "Cliente Servidor."

Presentaciones similares


Anuncios Google