Types of Transfer Networks generally provide two types
- Slides: 64
Types of Transfer • Networks generally provide two types of communication – Connection-oriented • reliable • stream based – Connectionless • unreliable • datagram based 3/6/2021 Java Networking 1
Connection-oriented Transfer Server Create Socket Accept Read/Write 3/6/2021 Client Connec tion Es tablish ment Communication Java Networking Create Socket Connect Read/Write 2
Connectionless Transfer Server Create Socket Client Create Socket Read/Write 3/6/2021 Communication Java Networking Read/Write 3
IP: Internet Protocol • IP is the workhorse protocol of the TCP/IP protocol suite • IP provides an unreliable, connectionless, datagram delivery service • RFC 791 is the official specification of IP 3/6/2021 Java Networking 4
The Workhorse User Process TCP 3/6/2021 User Process UDP transport ICMP IP IGMP ARP Hardware Interface RARP Java Networking application network link 5
Addressing • A distinction is made between names, addresses, and routes – A name indicates what we seek – An address indicates where it is – A route indicates how to get there • The internet protocol deals primarily with addresses. It is the task of higher level protocols to make the mapping from names to addresses. 3/6/2021 Java Networking 6
IP Addresses • Every interface on the internet must have a unique Internet Address (also called an IP address) • IP addresses are 32 -bits numbers • The addresses are not flat, they are divided into two components: the host address and the network address • The number of bits assigned to the host portion and network portion of the address varies depending on the class of the address 3/6/2021 Java Networking 7
IP Address Classes 7 bits Class A Class B Class C 0 1 1 24 bits netid hostid 0 14 bits 16 bits netid hostid 21 bits 8 bits netid hostid 28 bits Class D 1 1 1 0 multicast group ID 27 bits Class E 1 3/6/2021 1 0 (reserved for future use) Java Networking 8
Dotted Decimal Notation • IP addresses are normally written as four decimal numbers, one for each byte of the address. – 129. 21. 38. 169 3/6/2021 Java Networking 9
Assigning IP Addresses • Since every interface must have a unique IP address, there must be a central authority for assigning numbers • That authority is the Internet Network Information Center, called the Inter. NIC. • The Inter. NIC assigns only network ids, the assignment of host ids is up to the system administrator 3/6/2021 Java Networking 10
DNS • DNS (Domain Name System), a database that is used by TCP/IP applications to map machine names to IP addresses • No single site on the Internet knows all the information, each site maintains its own database of information and runs a server program that other systems across the Internet can query. • RFC 1034 and RFC 1035 describe DNS. 3/6/2021 Java Networking 11
DNS Basics • DNS breaks the Internet into domains • Within each domain there is an administrator who is responsible for assigning names within that domain • The domains in DNS are hierarchical • A complete DNS names includes all of the names in the path from the top-level domain down to the domain in which the machine resides 3/6/2021 Java Networking 12
The Top-Level Domains 3/6/2021 Java Networking 13
The Generic Domains • Even though the original intention was that any educational institution anywhere in the world could be registered under the EDU domain, in practice, it turned out with few exceptions, only those in the US have registered under EDU • This is basically the same in the other top-level domains with the exception of GOV and MIL. 3/6/2021 Java Networking 14
The Country Domains • In other countries, everything is registered under the 2 -letter country code, often with some subdivision. • For example, in Korea (KR) the second level names are AC for academic community, CO for commercial, GO for government, and RE for research. However, each country may go its own way about organizing its domain. 3/6/2021 Java Networking 15
DNS Basics 3/6/2021 Java Networking 16
The US Domain • Because organizations in the US have registered primarily in the EDU and COM domains, the US domain was rarely used. • The US Domain has grown and includes: – federal, state, country and city government agencies, K 12 schools, community colleges, technical/vocational schools, private schools, and libraries. 3/6/2021 Java Networking 17
The US Domain • The US Domain is based on political geography. – A basic name under US is the state name, then the "locality" name, (like a city, or county) then organization or computer name and so on. • Special names are used: – FED, STATE, AGENCY, DISTRICT, K 12, LIB, CC, CITY, and COUNTY. 3/6/2021 Java Networking 18
Transmission Control Protocol • TCP provides a connection-oriented, reliable, byte stream service (RFC 793) • TCP is an independent, general purpose protocol that can be adapted for use with delivery systems other than IP. • The term connection-oriented means that two applications using TCP must establish a TCP connection with each other before they can exchange data. 3/6/2021 Java Networking 19
TCP Ports • TCP uses protocol port numbers to identify the ultimate destination within a machine. • TCP uses the connection, not the protocol port, as its fundamental abstraction; connections are identified by a pair of endpoints. For example, (129. 3. 17. 253, 1069) and (129. 3. 17. 1, 1000). • Because a connection is identified by a pair of endpoints, a given TCP port number can be shared by multiple connections on the same machine. 3/6/2021 Java Networking 20
User Datagram Protocol • UDP is a simple, unreliable, datagramoriented, transport layer protocol (RFC 768). 0 15 16 -bit source port 16 31 16 -bit destination port 8 bytes 16 -bit length 16 -bit checksum data (if any) 3/6/2021 Java Networking 21
Java Net Classes Class Description Datagram. Packet This class represents a datagram packet. Datagram. Socket This class represents a socket for sending and receiving datagram packets. Inet. Address This class represents an Internet Protocol (IP) address. Multicast. Socket The multicast datagram socket class is useful for sending and receiving IP multicast packets. Server. Socket This class implements server sockets. Socket This class implements client sockets (also called just "sockets"). URL A pointer to a "resource" on the World Wide Web. URLConnection The superclass of all classes that represent a communications link between an application and a URL. 3/6/2021 Java Networking 22
Class Inet. Address public boolean equals(Object obj); public public byte[] static String static get. Address(); Inet. Address[] get. All. By. Name(String host); Inet. Address get. By. Name(String host); get. Host. Name(); Inet. Address get. Local. Host(); public int hash. Code(); public String to. String(); This class represents an Internet Protocol (IP) address. Applications should use the methods get. Local. Host(), get. By. Name(), or get. All. By. Name() to create a new Inet. Address instance. 3/6/2021 Java Networking 23
Host. Info. java import java. net. *; public class Host. Info { public static void main( String args[] ) { Inet. Address ip. Addr; try { ip. Addr = Inet. Address. get. Local. Host(); System. out. println( "This is " + ip. Addr ); } catch ( Unknown. Host. Exception ex ) { System. out. println( "Unknown host" ); } } 3/6/2021 Java Networking 24
Resolver. java import java. net. *; public class Resolver { public static void main( String args[] ) { Inet. Address ip. Addr; try { ip. Addr = Inet. Address. get. By. Name( args[0] ); System. out. print( "IP address = " + ip. Addr + "n " ); } catch ( Unknown. Host. Exception ex ){ System. out. println( "Unknown host " ); } } } 3/6/2021 Java Networking 25
Daytime Service Most UNIX servers run the daytime service on TCP port 13. cobalt> telnet kiev. cs. rit. edu 13 Trying 129. 21. 38. 145. . . Connected to kiev. Escape character is '^]'. Fri Feb 6 08: 33: 44 1998 Connection closed by foreign host. It is easy to write a Java daytime client. All the program needs to do is to establish a TCP connection on port 13 of a remote host. A TCP style connection is made using the Socket class. 3/6/2021 Java Networking 26
Class Socket // Constructors (partial list) public Socket(Inet. Address address, int port); public Socket(String host, int port); // Methods (partial list) public void close(); public Inet. Address get. Inet. Address(); public int get. Local. Port(); public Input. Stream get. Input. Stream(); public Output. Stream get. Output. Stream(); public int get. Port(); public String to. String(); 3/6/2021 Java Networking 27
Class Socket • This class implements client sockets (also called just sockets). A socket is a end point for communication between two machines. • The actual work of the socket is performed by an instance of the Socket. Impl class. • It is possible to modify some TCP parameters: – SO_LINGER – SO_TIMEOUT – TCP_NODELAY – Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). 3/6/2021 Java Networking 28
Day. Time. Client. java import java. net. *; import java. io. *; import java. util. *; public class Day. Time. Client { static int day. Time. Port = 13; public static void main(String args[]) { try { Socket sock = new Socket(args[0], day. Time. Port); Buffered. Reader din = new Buffered. Reader( new Input. Stream. Reader(sock. get. Input. Stream())); String r. Time = din. read. Line(); System. out. println(r. Time); sock. close(); } catch (exception e) {} } } 3/6/2021 Java Networking 29
A Java Daytime Server • It is easy to create a daytime server in Java (the only real problem is that your Java server will not be able to use port 13). • The server version of the program will use a Server. Socket to communicate with a client. • A Server. Socket will open a TCP port and wait for a connection. • Once a request is detected, a new port will be created, and the connection will be established between the client's source port and this new port. • Most servers listen for requests on a particular port, and then service that request on a different port. • This makes it easy for the server to accept and service requests at the same time. 3/6/2021 Java Networking 30
Class Server. Socket // Constructors (partial list) public Server. Socket(int port); public Server. Socket(int port, int count); // Methods (partial list) public Socket accept(); public void close(); public Inet. Address get. Inet. Address(); public int get. Local. Port(); public String to. String(); 3/6/2021 Java Networking 31
Class Server. Socket • A Server. Socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester. • The actual work of the Server. Socket is performed by an instance of the Socket. Impl class. • The abstract class Socket. Impl is a common superclass of all classes that actually implement sockets. It is used to create both client and server sockets. • A plain socket implements the Socket. Impl methods exactly as described, without attempting to go through a firewall or proxy. 3/6/2021 Java Networking 32
Day. Time. Server import java. net. *; import java. io. *; import java. util. *; public class Day. Time. Server { public static void main(String argv[]) { try { Date today = new Date(); Inet. Address local. Host = Inet. Address. get. Local. Host(); Server. Socket listen = new Server. Socket(0); System. out. println("Listening on port: "+listen. get. Local. Port()); for(; ; ) { Socket clnt = listen. accept(); System. out. println(clnt. to. String()); Print. Writer out = new Print. Writer(clnt. get. Output. Stream(), true); out. println(today); clnt. close(); } } catch(Exception e) {}}} 3/6/2021 Java Networking 33
Day. Time. Server in Action The output from the daytime server looks like this: kiev> java Day. Time. Server Listening on port: 36109 Socket[addr=cobalt/129. 21. 37. 176, port=32875, localport=36109] Socket[addr=localhost/127. 0. 0. 1, port=36112, localport=36109] The client output looks like this: cobalt> telnet kiev 36109 Trying 129. 21. 38. 145. . . Connected to kiev. Escape character is '^]'. Fri Feb 06 09: 53: 00 EST 1998 Connection closed by foreign host. 3/6/2021 Java Networking 34
Multi-Threaded Servers • It is quite easy, and natural in Java, to make a server multi-threaded. • In a multi-threaded server a new thread is created to handle each request. • Clearly for a server such as the daytime server this is not necessary, but for an FTP server this is almost required. • The code for the multi-threaded version of the server consists of a new class called Connection. • An instance of this class handles the clients request. 3/6/2021 Java Networking 35
Connection. java import java. net. *; import java. io. *; import java. util. *; class Connection extends Thread { protected Socket clnt; public Connection(Socket sock) { clnt = sock; this. start(); } public void run() { Date today = new Date(); try { Print. Writer out = new Print. Writer(clnt. get. Output. Stream(), true); out. println(today); client. close(); } catch (IOException e) {}}} 3/6/2021 Java Networking 36
TDay. Time. Server. java import java. net. *; import java. io. *; import java. util. *; public class TDay. Time. Server { public static void main(String argv[]) { try { Inet. Address local. Host = Inet. Address. get. Local. Host(); Server. Socket listen = new Server. Socket(0); System. out. println("Listening on: "+listen. get. Local. Port()); for(; ; ) { Socket clnt = listen. accept(); System. out. println(clnt. to. String()); Connection c = new Connection(client); } } catch(Exception e) { System. out. println("Server terminated"); } } } 3/6/2021 Java Networking 37
UDP Based Applications • UDP provides an unreliable packet based delivery service. An application that uses UDP must deal with the errors that can arise during communication. • The basic unit of transfer is called a Datagrams are small, fixed-length messages. • Datagram based services do have some advantages: – Speed – Message-oriented service. 3/6/2021 Java Networking 38
Datagrams • Datagram packets are used to implement a connectionless, packet based, delivery service. • Each message is routed from one machine to another based solely on information contained within that packet. • Multiple packets sent from one machine to another might be routed differently, and might arrive in any order. • Packets may be lost or duplicated during transit. • The class Datagram. Packet represents a datagram in Java. 3/6/2021 Java Networking 39
Class Datagram. Packet //Constructors public Datagram. Packet(byte ibuf[], int ilength); public Datagram. Packet( byte ibuf[], int ilength, Inet. Address iaddr, int iport); // Methods public synchronized Inet. Address get. Address(); public synchronized int get. Port(); public synchornized byte[] get. Data(); int get. Length(); void set. Address(Inet. Address iaddr); set. Port(int iport); set. Data(byte ibuf[]); set. Length(int ilength); 3/6/2021 Java Networking 40
Class Datagram. Socket • This class represents a socket for sending and receiving datagram packets. • Addressing information for outgoing packets is contained in the packet header. • A socket that is used to read incoming packets must be bound to an address (sockets that are used for sending must be bound as well, but in most cases it is done automatically). • There is no special datagram server socket class. • Since packets can be lost, the ability to set timeouts is important. 3/6/2021 Java Networking 41
Class Datagram. Socket // Constructors Datagram. Socket() Datagram. Socket(int port, Inet. Address iaddr) // Methods void close() Inet. Address get. Local. Address() int get. Local. Port() int get. So. Timeout() void receive(Datagram. Packet p) void send(Datagram. Packet p) set. So. Timeout(int timeout) 3/6/2021 Java Networking 42
Echo Services • A common network service is an echo server • An echo server simply sends packets back to the sender • A client creates a packet, sends it to the server, and waits for a response. • Echo services can be used to test network connectivity and performance. • There are typically different levels of echo services. Each provided by a different layer in the protocol stack. 3/6/2021 Java Networking 43
UDPEcho. Client. java import java. net. *; import java. io. *; import java. util. *; public class UDPEcho. Client { static int echo. Port = 7; static int msg. Len = 16; static int time. Out=1000; public static void main(String argv[]) { try { Datagram. Socket sock = new Datagram. Socket(); Datagram. Packet pak; byte msg[] = new byte[msg. Len]; Inet. Address echo. Host = Inet. Address. get. By. Name(argv[0]); pak = new Datagram. Packet(msg, msg. Len, echo. Host, echo. Port); sock. send(pak); sock. set. So. Timeout(time. Out); sock. receive(pak); } catch (Interrupted. IOException e) {System. out. println("Timeout"); } catch (Exception e) {} }} 3/6/2021 Java Networking 44
URLs • URL – URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet. – It's often easiest, although not entirely accurate, to think of a URL as the name of a file on the World Wide Web • A URL has two main components: Protocol Identifier http : //www. cs. rit. edu 3/6/2021 Java Networking 45
Creating a URL • An instance of the URL class can be used to represent a URL in Java – URL rit = new URL( http: //www. cs. rit. edu ); • The URL object created above represents an absolute URL. You can also create URL objects from a relative URL address – URL ptt = new URL( rit, “~ptt” ); • All of the URL constructors throw a Malformed. URLException if the arguments to the constructor refer to a null or unknown protocol. 3/6/2021 Java Networking 46
URL Methods • The URL class provides several methods that let you query URL objects. – You can get the protocol, host name, port number, and filename from a URL – Remember that not all URLs contain these components. 3/6/2021 Java Networking 47
Reading From A URL • After you have created a URL, you can call the URL's open. Stream() method to get a stream from which you can read the contents of the URL • The open. Stream() method returns a java. io. Input. Streamobject, so reading from a URL is as easy as reading from an input stream. • The URL knows how to talk HTTP to the server to fetch the resource identified by the URL. 3/6/2021 Java Networking 48
URLReader. java import java. net. *; import java. io. *; public class URLReader { public static void main(String[] args) { String source = "http: //dailynews. yahoo. com/tx/ts/summary. html"; try { URL yahoo = new URL( source ); Buffered. Reader in = new Buffered. Reader( new Input. Stream. Reader(yahoo. open. Stream())); String input. Line; while ((input. Line = in. read. Line()) != null) System. out. println(input. Line); in. close(); } catch ( Exception ex ) { ex. print. Stack. Trace(); }}} 3/6/2021 Java Networking 49
URLConnection • An abstract class that provides methods that can be used to read from and to write to the resource referenced by a URL • Invoking the open. Connection()method of the URL class returns a subclass of URLConnection that is capable of reading the protocol specified by the URL – Http. URLConnection – Jar. URLConnection 3/6/2021 Java Networking 50
Headlines. java import java. net. *; import java. io. *; public class Headlines { private static final String source = "http: //dailynews. yahoo. com/tx/ts/summary. html"; public static void main( String args[] ) { try { URL news. Source = new URL( source ); URLConnection news. Stream = news. Source. open. Connection(); HTMLTokenizer news = new HTMLTokenizer( new Buffered. Reader( new Input. Stream. Reader(news. Stream. get. Input. Stream()))); boolean ignore = true; String the. News = ""; 3/6/2021 Java Networking 51
Headlines. java while ( news. next. Token() != news. TT_EOF ) { if ( news. ttype == news. TT_TAG ) { if ( news. tag. Name. equals("b") ) ignore = false; else if ( news. tag. Name. equals( "/b" ) ) { ignore = true; if ( the. News. trim(). length() > 0 ) System. out. println( the. News ); the. News = ""; }else ignore = true; } else if ( !ignore && news. ttype == news. TT_WORD ) the. News = the. News + news. sval; else if ( !ignore ) the. News = the. News + (char)news. ttype; } } catch (Exception e) { e. print. Stack. Trace(); } } } // Headlines 3/6/2021 Java Networking 52
Java 1. 0 Security Model 3/6/2021 Java Networking 53
Java 1. 1 Security Model 3/6/2021 Java Networking 54
Java 1. 2 Security Model 3/6/2021 Java Networking 55
Class Security. Manager public abstract class java. lang. Security. Manager extends java. lang. Object { // Constructors protected Security. Manager(); // Methods (partial list) public void check. Accept(String host, int port); public void check. Access(Thread g); public void check. Access(Thread. Group g); public void check. Connect(String host, int port, Object context); // many, many others. . . } 3/6/2021 Java Networking 56
The Old Way class Tftp. Security. Manager extends Security. Manager { public void check. Link(String lib) {}; public void check. Property. Access(String key) {}; public void check. Connect(String host, int port, Object context) {}; public void check. Listen(int port) {}; public void check. Read(String s) { if (new File(s). is. Absolute() || s. index. Of("/")!=-1) throw new Security. Exception("Access to file: "+s+" denied"); } } public class Sec. Tftp. Server { public static void main(String argv[]) { System. set. Security. Manager(new Tftp. Security. Manager()); 3/6/2021 Java Networking 57
Protection Domains • A protection domain conceptually encloses a set of classes whose instances are granted the same set of permissions. • Protection domains are determined by the policy currently in effect. • The Java application environment maintains a mapping from code (classes and instances) to their protection domains and then to their permissions 3/6/2021 Java Networking 58
Mapping Classes To Domains Class Domain Permissions a. class b. class c. class d. class e. class Domain A Permissions Domain B Permissions Security Policy 3/6/2021 Java Networking 59
Domain Categories Protection domains generally fall into two distinct categories: system domain and application domain. It is important that all protected external resources, such as the file system, the networking facility, and the screen and keyboard, be accessible only via system domains. 3/6/2021 Java Networking 60
Permission Classes • The permission classes represent access to system resources. • The java. security. Permission class is an abstract class and is subclassed, as appropriate, to represent specific accesses. • As an example of a permission, the following code can be used to produce a permission to read the file named "abc" in the /tmp directory: – perm = new java. io. File. Permission("/tmp/abc", "read"); 3/6/2021 Java Networking 61
Policy Files • In the default Policy implementation, the policy can be specified within one or more policy configuration files. • The configuration files indicate what permissions are allowed for code from specified code sources. • A policy configuration file essentially contains a list of entries. It may contain a "keystore" entry, and contains zero or more "grant" entries. 3/6/2021 Java Networking 62
java. policy. all grant { permission java. security. All. Permission; }; % java –Djava. security. policy=java. policy. all my. App 3/6/2021 Java Networking 63
Example grant signedby “Duke” { permission java. io. File. Permission “/tmp/*”, “read, write”; }; 3/6/2021 Java Networking 64
- Diff between virtual circuit and datagram network
- Basestore iptv
- Style transfer
- What is disturbance that transfers energy
- Two port networks
- Types of telecommunication networks
- Collapsed backbone topology
- Storage area network examples
- Secondary storage device definition
- Rrpdata
- What causes lightning brainpop
- Sound waves from a radio generally travel in which medium?
- Introductory prepositional phrase
- In a minimum cardinality, minimums are generally stated as
- Learning is defined as relatively ___ in behaviour.
- John is generally pleasant
- Comma after generally
- Epiphytes plants
- Parts of a business letter quiz
- An access matrix is generally dense
- How to drape a client for a shampoo
- Commercial paper in finance
- Culture and society are intricately related
- Generally restful like the horizon where the sky meets land
- Shapes that have smooth even edges and are measurable
- Generally restful like the
- Generally, people use facial management techniques to
- Identity foreclosure example in movies
- Generally accepted accounting principles (gaap) adalah
- It is generally refers to human movement
- Chapter 58 coronal polishing
- At the end of the 1800s, colonies were generally seen as a
- Service design generally differs from product design
- Integrated development environment definition
- Scientifically minded people
- Which type of drugs are distributed by the envelope method
- Parts of haircutting shears milady
- Gaap constraints
- First christian martyr
- At stp which substance is the best conductor of electricity
- Revolved view
- Non metals
- Introduction to digital system design
- Information retrieval generally refers to
- Accounting principles are generally based on
- Etvx stands for tcs
- Progressive reformers attacked political machines because
- Allport theory
- Generally speaking proteins that come from animal sources
- A note is generally defined as:
- Mrp operations management
- Lexicon rap group
- Local winds and global winds
- A purposeful refusal to become generally involved
- Bryophytes include
- Front
- Detonation occurs in a reciprocating aircraft engine when
- What is heat
- Type of heat
- A lava lamp is an example of which type of heat transfer
- Which of the following are arithmetic micro operations ?
- Types of transfer stations in solid waste management
- How is conduction transferred
- The united states ought to provide a universal basic income
- How did the valet prepare guest clothes?