NETWORKING EN JAVA CLASSES IN THE JDK...

Ligista19 6 views 9 slides Jun 13, 2024
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

Java es un lenguaje de programación y una plataforma informática que fue comercializada por primera vez en 1995 por Sun Microsystem


Slide Content

NETWORKING EN JAVA Ing. Geovanny Vega Villacís, MTC

NETWORKING CLASSES IN THE JDK Through the classes in java.net, Java programs can use TCP or UDP to communicate over the Internet. – The InetAddress, URL, URLConnection . – Socket, and ServerSocket classes all use TCP to communicate over the network. – The DatagramPacket , DatagramSocket , and MulticastSocket classes are for use with UDP

Accessing TCP/IP from Java is straightforward. The main functionality is in the following classes: – java.net.InetAddress : Represents an IP address (either IPv4 or IPv6) and has methods for performing DNS lookup (next slide). – java.net.Socket : Represents a TCP socket. – java.net.ServerSocket : Represents a server socket which is capable of waiting for requests from clients.

INETADDRESS • The InetAddress class is used to encapsulate both the numerical IP address and the domain name for that address. • We interact with this class by using the name of an IP host, which is more convenient and understandable than its IP address. • The InetAddress class hides the number inside. Servers InteAddress have three main purposes: Encapsulates an address Performs name lookup (converting a host name into an IP address) Performs reverse lookup (converting the address into a host name)

Factory Methods InetAddress • static InetAddress getLocalHost ( ) throws UnknownHostException • static InetAddress getByName ( String hostName ) throws UnknownHostException • static InetAddress[ ] getAllByName ( String hostName ) throws UnknownHostException

Getter Methods public boolean isMulticastAddress () public String getHostName () public byte[] getAddress () public String getHostAddress ()

Utility Methods public int hashCode () public boolean equals(Object o) public String toString ()

Clases útiles en comunicaciones con Sockets Socket ServerSocket DatagramSocket DatagramPacket MulticastSocket NetworkServer NetworkClient SocketImpl

Socket obtiene recursos IP import java.net.*; public class DireccionesIP { String name ; public String Nombre(){ // Obtiene nombre LocalHost try{ InetAddress address = InetAddress.getLocalHost (); name = address.getHostName ();} catch ( UnknownHostException e){ name ="Imposible determinar Nombre del Equipo";} return name ; } public String IP(){ // Obtiene Dirección IP LocalHost try{ InetAddress address = InetAddress.getLocalHost (); name = address.getHostAddress ();} catch ( UnknownHostException e){ name ="Imposible determinar Nombre del Equipo";} return name ; } }
Tags