Descargar la presentación
La descarga está en progreso. Por favor, espere
Publicada porAlberto Quintero Farías Modificado hace 9 años
1
User Datagram Protocol UDP Juan Pablo Araneda Danilo Araya Z.
2
La Idea... Proveer a las aplicaciones de un servicio de mensajes simple con un protocolo no confiable.
3
Para establecer una comunicación confiable se requieren MUCHOS mensajes de control. Esto hace que una comunicación confiable se justifique solo cuando tenemos una alta relación: Por que usar un protocolo no confiable?
4
Aplicaciones mas comunes sobre UDP ECHO Hola!! Cual es la dirección IP de lucas.elo.utfsm.cl? 200.1.17.130 Domain Name Service (DNS)
5
Características de UDP No orientado a la conexión. Control de errores opcional. Trabaja en base a puertos. Puertos “bien conocidos” para servicios estándar (0-1023). Puertos para asignación dinámica (1024-65535).
6
Puertos. Host lucas ECHO 7 DNS 53 TIME 37 Que numero IP tiene lucas? Hola!!Que hora es? Hola!! Son las 14:15 200.1.17.130
7
Estructura del Header. Puerto de origen Puerto de destino Tamaño del datagrama Suma de control 01631 Datos Incluye el header minimo 8 máximo 65535 Opcional: Si no se usa es Cero
8
Pseudo Header Se usa para calcular el Checksum. No se transmite!! Se debe generar en el origen para calcular el Checksum y luego en el destino para verificarlo. Tiene la ventaja agregada de verificar el origen y el destino.
9
Pseudo Header 00000000 01631 Dirección IP de origen Dirección IP de destino Protocolo =17 Tamaño de la UDP
10
Procedimiento de envío Header Pseudo Header Checksum Data Pseudo Header Checksum ORIGENDESTINO Header Checksum Data
11
Bibliografía Internetworking with TCP/IP Douglas Comer Volume I: Principles, Protocols and Architecture. 3era Edición. TCP/IP Arquitectura, protocolos e Implementación con IPv6 y seguridad de IP Dr Sidnie Feit. RFC 768 “User Datagram Protocol”
12
Ejemplo de aplicación UDP Servidor de eco Hola!!
13
Listado del Servidor class echoServerThread extends Thread { private DatagramSocket socket = null; echoServerThread() { super("echoServer"); try { socket = new DatagramSocket(); System.out.println("echoServer listening on port: " + socket.getLocalPort()); } catch (java.net.SocketException e) { System.err.println("Could not create datagram socket."); }
14
Listado del Servidor public void run() { if (socket == null) return; while (true) { try { byte[] buf = new byte[256]; DatagramPacket packet; InetAddress address; int port; String dString = null;
15
// receive request packet = new DatagramPacket(buf, 256); socket.receive(packet); address = packet.getAddress(); port = packet.getPort(); buf = packet.getData(); // send response packet = new DatagramPacket(buf, buf.length, address, port); socket.send(packet); } catch (IOException e) { System.err.println("IOException: " + e); e.printStackTrace(); } protected void finalize() { if (socket != null) { socket.close(); socket = null; System.out.println("Closing datagram socket."); }
16
Listado del Cliente class echoUDP { public static void main(String[] args) { int port; InetAddress address; DatagramSocket socket = null; DatagramPacket packet; byte[] sendBuf = new byte[256]; byte[] recvBuf = new byte[256]; if (args.length != 3) { System.out.println("Use: java echoUDP "); return; }
17
try { // bind to the socket socket = new DatagramSocket(); } catch (java.net.SocketException e) { System.err.println("Could not create datagram socket."); } if (socket != null) { try { // send request port = Integer.parseInt(args[1]); address = InetAddress.getByName(args[0]); sendBuf = args[2].getBytes(); packet = new DatagramPacket(sendBuf, sendBuf.length, address, port); socket.send(packet);
18
// get response packet = new DatagramPacket(recvBuf, 256); socket.receive(packet); String received = new String(packet.getData()); System.out.println("Respuesta: " + received); System.out.println("Chao!!"); socket.close(); } catch (IOException e) { System.err.println("IOException: " + e); e.printStackTrace(); }
Presentaciones similares
© 2024 SlidePlayer.es Inc.
All rights reserved.