Java Network Programming Tutorial

java network programming and distributed computing networked applications and java network programming lecture notes, java network programming framework
OliviaCutts Profile Pic
OliviaCutts,France,Teacher
Published Date:01-08-2017
Your Website URL(Optional)
Comment
Java Network Programming Java Network Programming Study Guide Professor Wanlei Zhou School of Information Technology Deakin University 1 Java Network Programming 0. Unit Outline 0.1. Objective The objective of this unit is to provide an up-to-date knowledge of network programming in Java to students. It covers most, if not all, aspects of Java network programming facilities. First, the lower level Java networking is overviewed which includes communication with sockets, Web URLs, and datagrams. Second, higher-level object- oriented networking is addressed which includes communication with homogenous RMI (remote method invocation) and heterogeneous CORBA (common object request broker architecture) in IDL (interface definition language). The unit also covers topics related to JDBC, concurrent programming, security, servlets, and Java Beans. At the end of this unit, students should be familiar with the basic concepts, the architectures, the protocols, the advantages and limitations, and the recent development of various Java network programming technologies. The knowledge gained from the study of this unit will enable students to create network applications using the Java language. Students will also have adequate knowledge in tracking the current and future development in network programming in Java. The Study Guide is divided into three parts. The first part (Sessions 1 and 2) overviews the fundamental knowledge required for this unit, including Java basics, communication systems, and the client-server model for network computing. The second part (Sessions 3, 4, 5, 6, 7, and 8) introduces the techniques used in Java network computing, including Java streams, connection-oriented communication in Java, developing Java programs for clients and servers, connectionless communication in Java, and multithreading in Java.. The third part (Sessions 9, 10, 11 and 12) addresses some advanced issues in Java networking, such as JDBC, Java RMI and CORBA, Java Servlets and Java Beans, and Java security. 0.2. Text Books 0.2.1. Main Text Book Couch, Justin. “Java 2 networking,” Justin Couch, New York : McGraw-Hill, c1999 (JC). 0.2.2. Reference Books • “Beginning Java Networking,”, C. Darby et al., Wrox Press Ltd., 2001, ISBN: 1- 861005-60-1 (BJN). nd • “Java Network Programming.” 2 ed., E. R. Harold, O’Reilly, 2000. ISBN: 1- 56592-870-9 (JNP). nd • “Java Network Programming”, 2 ed., M. Hughes, M. Shoffner, and D. Hamner, Manning Publishing Co., 1999, ISBN: 1-884777-49-X HSH 9 Java Network Programming • “Java Distributed Computing”, J. Farley, O’Reilly, 1998, ISBN: 1-56592-206-9 FAR. • “Java 2 Developer’s Handbook”, P. Heller and S. Roberts, Sybex, 1999, ISBN: 0- 7821-2179-9 Java2H • “Java 1.2 Unleashed”, J. Jaworski,: Macmillan Computer Publishing, 1998, ISBN: 1575213893 Java2U 0.3. Assessment • Progressive assessment 40% • Examination 60% 10 Java Network Programming 1. Java Language Basics 1.1. Study Points • Understand the basic principles of the Java programming language. • Be able to complete small programs in Java. • Be familiar with object-oriented programming using Java. • Be familiar with Java Applets. • Be able to design simple user interfaces using Java AWT. Reference: (1). Reader 1. “Learning Java Programming by Examples”, by Wanlei Zhou, Lessons 1 through 9. (2). Java2H: Part 1, Chapters 1-5. (3). Java2U Chapters 1-10. 1.2. The Java Development Kit Although this unit assumes that students have a basic knowledge in Java, students without Java knowledge can still study this unit without much trouble. I have assembled a special document (Reader 1) for those who have little knowledge in Java. Experiences show that most students with a basic programming knowledge in any other languages such as C or C++ can have a good understanding in Java in a week through the help of the document. Students with a solid knowledge in Java can skip this session. One comment about the example programs in Reader 1: they were accumulated over a period where Java versions have been fast evolving. Therefore, some of the programs may include deprecated methods for later Java versions. 1.2.1. The JDK The Java Development Kit (JDK), created by Sun’s JavaSoft subsidiary, is Java’s base software environment. It includes all the software and documentation necessary to create Java applications or applets, and commands used to compile, run, package, and debug Java programs. Figure 1.1 shows how a Java program is created. Figure 1.1. Creation of Java programs 11 Java Network Programming The JDK is available on various operating systems in which the Java Core Application Program Interface (API), a standard library of classes for Java applications and applets, is guaranteed to execute on all Java implementations. Java programming language has gone through a number of versions. Many examples of this unit are based on Java 2, aka JDK 1.2, the currently widely used version. Some features introduced in this unit need JDK 1.3. Currently Sun makes a Java Development Kit (JDK) freely available for Windows operating systems and Solaris. You can download it from http://java.sun.com/products/jdk/1.2/. The JDK 1.2 API consists of 57 packages, all of which are in the Core API. Of the 53 Core API packages, 22 are part of the Java Foundations Classes (JFC). The Core API is the minimum subset of the Java API that must be supported by the Java Platform. All classes and interfaces that are part of the JDK but are not in the Core API are in the Standard Extension API. The JFC are Core API classes and interfaces that support GUI development for applets and applications. 1.2.2. The Java Virtual Machine All compiled Java programs are Java classes. The Java virtual machine (JVM) is a software implementation of a CPU designed to run Java programs. Since JVM is typically not implemented in hardware, hence the term of virtual. The JVM is a software layer that enables Java to be independent of physical CPU type. Therefore, Java programs can be executed on any platform as long as the JVM is installed. Java programs can be applets or pure Java applications. Java applications are Java programs that do not require a WWW browser. These applications run under the JDK’s java command and are started from a user’s command line or shell script. A Java application should contain a public static void main method (equivalent to a main() function in C). Java applets are Java programs that are downloaded from WWW sites and executed in web browsers. This is the most popular use of Java programs to deliver network-based applications through WWW sites and web browsers. Instead of a main() method, applets use methods suited to downloaded programs that display output in a web browser window. 1.3. Java Basics 1.3.1. Introductory Lessons on Java Students are encouraged to read lessons 1, 2, 3, and 4 of Reader 1 and test run all the programs in these four lessons. In lesson 1, we introduce a number of “first” Java programs, including a few simple examples of Java application and applet. We then introduce the concepts of object-oriented programming using Java and basic font in Java. In lesson 2, we introduce some basic components of the Java language, including the dates, strings, arrays, loops. We also introduce some mechanisms for parameter passing, argument handling, and type converting. 12 Java Network Programming In lesson 3, we outline the principles of object-oriented programming in Java, including the constructors and inheritance. In object-oriented programs data is represented by objects. Objects have two sections, fields (instance variables) and methods. Fields tell you what an object is. Methods tell you what an object does. These fields and methods are closely tied to the object's real world characteristics and behavior. When a program is run messages are passed back and forth between objects. When an object receives a message it responds accordingly as defined by its methods. Most Java programs are organised using the object-oriented concepts. In lesson 4, we emphasis on the principles of applet design since applets are the major mechanism of network programming in Java. We concentrate on topics of the HTML pages related to applets, the alignment and passing parameters. Each topic of a lesson is illustrated using simple examples. Students are encouraged to test run these examples and understand the Java components and statements illustrated in these examples. 1.3.2. Applets According to Sun, "An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application....The Applet class provides a standard interface between applets and their environment." There are four definitions of applet: • A small application • A secure program that runs inside a web browser • A subclass of java.applet.Applet • An instance of a subclass of java.applet.Applet Applets are executed in the “sandbox” of the Java virtual machine of a web browser. An applet can: • Draw pictures on a web page • Create a new window and draw in it. • Play sounds. • Receive input from the user through the keyboard or the mouse. • Make a network connection to the server from which it came and can send to and receive arbitrary data from that server. Anything you can do with these abilities you can do in an applet. However, an applet cannot: • Write data on any of the host's disks. • Read any data from the host's disks without the user's permission. In some environments, notably Netscape, an applet cannot read data from the user's disks even with permission. 13 Java Network Programming • Delete files. • Read from or write to arbitrary blocks of memory, even on a non-memory- protected operating system like the MacOS. All memory access is strictly controlled. • Make a network connection to a host on the Internet other than the one from which it was downloaded. • Call the native API directly (though Java API calls may eventually lead back to native API calls). • Introduce a virus or trojan horse into the host system. • An applet is not supposed to be able to crash the host system. However in practice Java isn't quite stable enough to make this claim yet. 1.4. Further Topics in Java We use five lessons (lessons 5, 6, 7, 8, and 9) in the Reader 1 document to introduce some further topics in Java programming. 1.4.1. Graphics and Colors In lesson 5, we introduce the topic on graphics and colours, in particular, we illustrate the use of lines and rectangles, the creation of polygons, ellipses, and arcs, and the use of different fonts and colours. Apart from examples on each feature, we also use an example to illustrate the use of all these features. 1.4.2. Animation, Image, Threads, Sounds and the Use of Swing In lesson 6, we introduce the use of animation, images, threads, sound and the use of Swing. This lesson consists of examples of a digital clock, the colurs swirl, the use of images and the adjustment of images, some simple animation mechanisms, such as a bouncing circle and an animated cat, and also some techniques in using sound. 1.4.3. Events Handling In lesson 7, we introduce the use of events and interactivity in Java. We use examples to illustrate the techniques to draw spots, normal lines and scribble lines. We then introduce the mechanism of keyboard control and event handling in different versions of Java JDK. 1.4.4. Abstract Windowing Toolkit In lesson 8, we introduced the use of the abstract windowling toolkit (AWT), a graphics tool package provided by the JDK. In particular, we introduced the use of buttons, check boxes, radio buttons, choice menus, and text fields. We then introduce the mechanisms for flow layout, grid layout, and border layout. In addition to examples for each topic, we finally use an example of a color switcher to illustrate the use of all these features. In lesson 9, we introduce some advanced usage of the AWT. In particular, we illustrate the use of text areas, the mechanism to scroll a list of text, the use of sliding bar, simple 14 Java Network Programming pop-up windows, pop-up windows with dialogue, and pop-up windows with dialogu and menu. We also introduce the technique to create links inside applets in this lesson. Reader 1 also contains other lessons related to networking programming. You can skip these lessons since they will be covered in more details in the following sessions. 1.5. Java Versions and Network APIs 1.5.1. Java Versions Java 1.0 gave the programmer the basic networking capability, such as connecting to other computers and listening to connection requests from other computers. On top of the basic capability, some APIs, such as the Universal Resource Locator (URL) handlers, for high-level Internet related protocols were provided. However, using the Java 1.0 to create large-scale applications was difficult since it was hard to customize connections.. Java 1.1 added more control over the connections to the APIs. These options allowed the Java programmer to build networked programs with a similar quality as programs built using native code. It also added the ability to create customized network handlers while still retaining the high-level URL handler capabilities. The third useful part added to the Java 1.1 version is the ability to create multicast connections within Java code. Java 1.2 (Java 2) introduced few changes in terms of network computing capability. The only real new change was the new fine-grain security model, but in day-to-day application programming, it is not much of an issue. In Java 2, the changes moved to the supporting APIs. APIs that relied on the core networking capabilities had a lot more functionality added to them. Java version 1.3 is an enhancement to Java 2, Standard Edition (J2SE). It includes a new Java virtual machine (VM)the Java HotSpot Clientwhich is aimed at improving client performance in an enterprise desktop.. The Java HotSpot Client VM is totally new, the emphasis is having it tuned for client performancereducing application start-up time, how quickly an application comes to life on a desktop. Java 1.3 also added support for lightweight directory access protocol (LDAP), which gives a desktop client directory connectivity to access information across the enterprise, said Connell. J2SE 1.3 also has new Java applet caching functionality, which will enable a developer to deploy a Web application more quickly by downloading and storing Java applets on a local hard drive for immediate access. 1.5.2. Java Networking APIs Java networking APIs are provided in a series of layered abstractions on which the programmer can decide to work. Java’s basic networking capabilities are split between the java.net and the java.io packages. Programmers are able to use these packages to establish and communicate over a network connection and pass moderately complex data over it. Once a connection has been established, there are a number of opportunities for the programmer, e.g., defining custom protocols, using existing protocols, or building a 15 Java Network Programming higher-level API on top of the basic services. Java provides a number of these APIs. At the bottom of the heap are the URL content handlers contained in the java.net package. Next in the line is the Remote Method Invocation (RMI), which uses java.net and java.io to implement its functionality as well as a good deal of native code. RMI comes in a number of packages: java.rmi, java.rmi.dgc, java.rmi.registry, and java.rmi.server. RMI uses the network facilities to pass references to Java classes over the network. Another two Java techniques, the Java servlets and Java Beans, can be regarded as function-oriented mechanisms. Servlets can be viewed as server-side applets in which they responds to client requests via the HTTP protocol. Java Beans are based on the component-based system concepts, in which reusable components can be distributed across the network. 16 Java Network Programming 2. Network Communication and the Client-Server Model 2.1. Study Points • Understand the Internet protocol architecture. • Understand the basic concepts of the TCP/IP protocol suit. • Understand the IPv6 concepts. • Understand the basic client-server model. • Understand the extensions to the basic client-server model and the service discovery mechanisms. • Be familiar with the mechanisms in client-server communication • Understand the different semantics of message passing. • Understand the RPC mechanism. Reference: (1). Any book on computer networks. (2). A. Goscinski and W. Zhou, “The Client-Server Model and Systems”, Technical Report, Deakin University, TR C97/04, 1997. 2.2. Communication Protocol Architectures 2.2.1. The OSI Protocol Architecture The OSI (Open System Interconnection) Reference Model was developed by ISO (International Standards Organisation) as a model for implementing data communication between cooperating systems. It has seven layers. • Application: providing end-user applications. • Presentation: translating the information to be exchanged into terms that are understood by the end systems. • Session: for the establishment, maintenance, and termination of connections. • Transport: for reliable transfer of data between end systems. • Network: for routing the data to its destination and for network addressing. • Data link: preparing data in frames for transfer over the link and error detection and correction in frames. • Physical: defining the electrical and mechanical standards and signaling requirements for establishing, maintaining, and terminating connections. Figure 2.1 depicts the OSI process and peer-to-peer communication, where SDU represent service data unit, Hi (i = 2 … 7) headers of layer i, and T2 is the trailer for layer 17 Java Network Programming 2. Figure 2.1 OSI process and peer-to-peer communication 2.2.2. Internet Architecture Internet is the largest data network in the world. It is an interconnection of several packet- switched networks and has a layered architecture. Figure 2.2 shows the comparison of Internet and OSI architectures. Figure 2.2 Comparison of Internet and OSI architectures Internet layers: 18 Java Network Programming • Network access layer: It relies on the data link and physical layer protocols of the appropriate network and no specific protocols are defined. • Internet layer: The Internet Protocol (IP) defined for this layer is a simple connectionless datagram protocol. It offers no error recovery and any error packets are simply discarded. • Transport layer: Two protocols are defined: the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). TCP is a connection-oriented protocol that permits the reliable transfer of data between the source and destination end users. UDP is a connectionless protocol that offers neither error recovery and nor flow control. • User process layer (application): It describes the applications and technologies that are used to provide end-user services. 2.3. BSD Internet Domain Sockets The ARPANET sponsored by the Advanced Research Projects Agency (ARPA) and developed during late 1960s and early 1970s is a milestone for computer networks. In the early 1980s, a new family of protocols was specified as the standard for the ARPANET. Although the accurate name for this family of protocols is the “DARPA Internet protocol suite,” it is commonly referred as the TCP/IP protocol suite, or just TCP/IP. The Internet domain sockets on BSD UNIX use the TCP/IP protocol suite as the communication protocols among processes generally located on different computers across a network. We introduce the TCP/IP in this section. 2.3.1. Overview Communications between computers connected by computer networks use well-defined protocols. A protocol is a set of rules and conventions agreed by all of the communication participants. As we have mentioned, in the OSI reference model, the communication protocols are modelled in seven layers. Layered models are easier to understand and make the implementation more manageable. A protocol suite is defined as a collection of protocols from more than one layer that forms a basis of a useful network. This collection is also called a protocol family. The TCP/IP protocol suite is an example. There are many protocols defined in the TCP/IP protocol suite. We are going to describe three of them: the Transport Control Protocol (TCP), the User Datagram Protocol (UDP) and the Internet Protocol (IP). If using OSI reference model the TCP and UDP protocols are Transport layer protocols, while the IP protocol is a Network layer protocol. Figure 2.3 illustrates the relationship of these protocols and their positions in the OSI reference model. 19 Java Network Programming Figure 2.3. The Layered TCP/IP protocol suite The TCP protocol is a connection-oriented protocol that provides a reliable, full-duplex, byte stream for interprocess communications. The UDP protocol, on the other hand, is a connectionless protocol that provides an unreliable datagram service: there is no guarantee that UDP datagrams ever reach their intended destination. Acknowledgement must be used in order to provide reliable services when using the UDP protocol. 2.3.2. Network Layer: IP The IP protocol is connectionless and unreliable. It is based on internet datagrams. The protocol takes a datagram from the transport layer (for example, from the TCP protocol). A datagram is up to 64k bytes long and it may be part of a longer message. Each datagram is transmitted over the network independently so the communication ls connectionless. During transmission, a datagram may be lost or may be further fragmented into smaller units (called IP packets) as it goes through the protocol layers. When all the IP packets of a datagram finally arrive the destination computer, they are reassembled to form the datagram and then transferred to the transport layer of the destination site. If any of the IP packets of a datagram are lost or corrupted, the entire datagram is discarded by the destination site so the IP protocol is therefore unreliable because it cannot guarantee the delivery of a datagram. The IP datagram consists of a header and a text part. The header includes information such as the type of service, the length of the header, the length of the text part, the address of the source computer, the address of the destination computer, and other information. 20 Java Network Programming It is the IP layer that handles the routing through networks. The Internet address is used to identify networks and computers and is used in an IP datagram header to denote the source and destination computer addresses. An Internet address has 32 bits and encodes both a network ID number and a host ID number. Every host on a TCP/IP internet must have a unique Internet address. The network ID numbers are assigned by some kind of authority, e.g., the Network Information Center (NIC) located at SRI International. While the host ID numbers are assigned locally. The common notation of an Internet address is to use 4 bytes, as shown in the following: field_1.field_2.field_3.field_4 Where 0 = field = 255 (FF ), 1 = i = 4. i 10 16 Depending on the network’s class (described below), the network number can be field , 1 or field .field or field .field .field. That means the host number can be 1 2 1 2 3 field .field .field , field .field or field . 2 3 4 3 4 4 Networks are classified into 3 classes, as listed in the next Table. Class Binary number of field Network ID (decimal) 1 A 000 000 – 0111 111 0 - 126 B 1000 000 – 1011 1111 128 – 191.254 C 1100 0000 – 1101 1111 192 – 223.254.254 A brief description of these classes follows: Class A: networks are the largest networks with more than 65,536 hosts. A class A network’s network ID number is field . 1 Class B: networks are mid-size networks with host IDs ranging from 256 to 65,536. A class B network’s network ID number is field .field . 1 2 Class C: networks are the smallest networks with up to 256 hosts A class C network’s network ID number is field .field .field . 1 2 3 Figure 2.4 illustrates the Internet address formats of these three network classes. 21 Java Network Programming Figure 2.4. Internet network classes For example, if we have an Internet address 98.15.12.63, we can tell that it is a class A network because field is within the range of 0 - 126. Its network ID number is 98 and 1 host ID number is 15.12.63. If we have an Internet address 130.194.1.106, we can tell that it is a class B network because the field .field is within the range of 128 - 191.254. 1 2 Its network ID number is 130.194 and host ID number is 1.106. Some IP addresses have significant meanings. For example, the address of 127.0.0.1 is the address of the local machine. It is used for allowing IP communications to the local machine so that sockets and other systems may run even the machine is isolated from the network. It is evident that an Internet address can only be assigned to one host. But a host can have several Internet addresses. This is because that in some situations, we want a host to be connected to several networks. Although an Internet address clearly specifies the address of a host, few persons want to use Internet addresses directly: they are too hard to remember. Domain Name System (DNS) is used to name host addresses in more human-oriented way and to find the Internet addresses corresponding to machine names. The DNS is a hierarchical naming system: its name space is partitioned into sub-domains, which can themselves be further divided. The DNS is also a distributed system: the name space is delegated to local sites that are responsible for maintaining their part of the database. Programs called name servers manage the database. The DNS name space can be represented as a tree, with the nodes in the tree representing domain names. A fully qualified domain name is identified by the components (nodes) of the path from the domain name to the root. A component is an arbitrary string of up to 63 octets in length; the length of a fully qualified domain name is limited to 256 octets. By convention, a domain name is written as a dot-separated sequence of components, listed right to left, starting with the component closet to the root. The root is omitted from the name. Thus, wan_res.cm.deakin.edu.au is a fully qualified domain names. It is certainly easier to be remembered than the corresponding Internet addresses 139.130.118.102. 22 Java Network Programming DNS name space is divided into zones of authority, and name servers have complete control of the names within their zones (domains). For easier management of domains, a large domain can be split into smaller sub-domains, and name servers can delegate authority to other name servers for sub-domains. For example, if edu.au represents the domain of all educational institutions in Australia, then deakin.edu.au and anu.edu.au are its two sub-domains. Queries for DNS information within sub-domain deakin.edu.au are first dealt with by the name server of this sub-domain. If this name server cannot answer a query, the query is then directed to the name server of edu.au domain. At last, the name server of the root can answer the query. 2.3.3. Transport Layer: TCP and UDP As we have shown in Figure 2.3, user processes interact with the TCP/IP protocol suite by sending and receiving either TCP data or UDP data. To emphasise that the IP protocol is used, we sometimes refer them as the TCP/IP or UDP/IP protocols. TCP provides a connection-oriented, reliable, full-duplex, byte-stream service, similar to a virtual circuit, to an application program. UDP, on the other hand, provides a connectionless, unreliable datagram service to an application program. As we mentioned in the previous section, the Internet address is used to identify networks and computers. In order to let many processes use the TCP or UDP simultaneously (these processes may reside on any computers of a network), both protocols use 16-bit integer port numbers for identifying data associated with each user process. The association of port numbers and user processes last as long as the communication, so the following 5- tuple uniquely identifies a communication: • the protocol (TCP or UDP), • the local computer’s Internet address, • the local port number, • the foreign computer’s Internet address, • the foreign port number. For example, if we have a communication using TCP protocol. The server is on a host with domain name of wan_res.cm.deakin.edu.au (Internet address 139.130.118.102), using port number 5100. The client is on a host with domain name of sky3.cm.deakin.edu.au (Internet address 139.130.118.5), using port number 5101. The 5- tuple which uniquely defines the communication is: tcp, 139.130.118.102, 5100, 139.130.118.5, 5101 Because the host name is easier to understand and there are some system calls to convert between a host name and its Internet address, the above 5-tuple can then be written as: tcp, wan_res.cm.deakin.edu.au, 5100, sky3.cm.deakin.edu.au, 5101 Because wan_res.cm.deakin.edu.au and sky3.cm.deakin.edu.au are within the same sub- domain, we can even write the 5-tuple as: tcp, wan_res, 5100, sky3, 5101 23 Java Network Programming There are some restrictions in using port numbers. In TCP and UDP, port numbers in the range 1 through 255 are reserved. All well-known ports (some commonly used utilities use these ports) are in this range. For example, the File Transfer Protocol (FTP) server uses the well-known port number 21 (decimal). Some operating systems also reserve additional ports for privileged usages. For example, 4.3BSD reserves ports 1-1023 for superuser processes. Only port numbers of 1024 or greater can be assigned by user processes. A TCP protocol entity accepts arbitrarily long messages from user processes, breaks them into datagrams of up to 64k bytes, and sends them to the IP layer. Before the real communication happens, a connection must be set up between the sender and the recipient. After the communication, the connection must be disconnected. As the IP layer does not guarantee the proper delivery of a datagram, it is the responsibility of the transport layer to ensure that a datagram arrives at the destination properly using time-out and retransmission techniques. Also as datagrams are transmitted independently, the datagrams of a message may arrive at the destination out of order and it is also the TCP protocol’s responsibility to reassemble them into the message in the proper sequence. Each datagram submitted by the TCP to IP layer contains a TCP header and a data part. The whole TCP datagram is viewed by the IP as data only and an IP header is added to form an IP datagram. The TCP header contains the source port number, the destination port number, the sequence number, and other information. The TCP protocol has a well-defined service interface. There are primitives used to actively and passively initiate connection, to send and receive data, to gracefully and abruptly terminate connections, and to ask for te status of a connection. A UDP protocol entity also accepts arbitrarily long messages from user processes, breaks them into datagrams of up to 64k bytes, and sends them to the IP layer. Unlike the TCP protocol, no connection is involved and to guarantee of delivery or sequencing. In effect, UDP is simply a user interface to IP. A header is also added into the datagram by UDP, which contains the source port number and the destination port number. 2.3.4. The Internet The current “Internet" can be defined as "the collection of all computers that can communicate, using the Internet protocol suite, with the computers and networks registered with the Internet Network Information Center (InterNIC)." This definition includes all computers to which you can directly send Internet Protocol packets (or indirectly, through a firewall). Internet Protocol enables communication between computers on the Internet by routing data from a source computer to a destination computer. However, computer-to-computer communication only solves half of the network communication problem. In order for an application program, such as a mail program, to communicate with another application, such as a mail server, there needs to be a way to send data to specific programs within a computer. 24 Java Network Programming Ports, or addresses within a computer, are used to enable communication between programs. An application server, such as a Web server or an FTP server, listens on a particular port for service requests, performs whatever service is requested of it, and returns information to the port used by the application program requesting the service. Popular Internet application protocols are associated with well-known ports. The server programs that implement these protocols listen on these ports for service requests. The well-known ports for some common Internet application protocols are shown in Table 2.1. Port Protocol 21 File transfer protocol (ftp) 23 Telnet protocol (telnet) 25 Simple Mail Transfer Protocol (SMTP) 80 Hypertext Transfer Protocol (HTTP) Table 2.1. Common Internet application protocols and their ports 2.4. The Next Generation Internet Protocol: IPv6 2.4.1. Why IPv6? The primary motivation for change from IPv4 to IPv6 is the limited address space. The 32-bit IP address can only include over a million networks in the Internet. At the current growth rate, each of the possible network prefixes will soon be assigned and no further growth will be possible. The second motivation for change comes from requirements of new applications, especially applications that require real-time delivery of audio and video data. The current IP has limited capabilities for routing real-time data. Challenges faced by IPv4 can be summarized: • Address spaces o growth of the Internet. Maximum: 4 billion o when will addresses run out? Estimates: 2005 o single IP addresses for devices • Mobile Internet o Internet services from everywhere o Removing location dependency • Security o End-to-end encryption Data Integrity, authentication Requirements for the new protocol can be summarized as follows: 25 Java Network Programming • Support billions of hosts • Reduce size of routing tables • Simplify protocol, process packets faster • Provide better security (authentication & privacy) • Better QoS (particularly for real-time data) • Aid multicasting, anycasting • Make it possible for a host to roam without changing its address 2.4.2. IPv6 Features IPv6 retains many design features of IPv4. It’s connectionless. IPv6 has the following new features: • Address size: Instead of 32, each IPv6 address is 128 bits. The address space is large enough for many years of growth of Internet. • Header format: The IPv6 header has a completely format compared to IPv4 headers. • Extension header: Unlike IPv4, which uses a single header format for all datagrams, IPv6 encodes information into separate headers. A datagram of IPv6 contains a base header followed by 0 or more extension headers, followed by data. • Support for audio and video. IPv6 includes a mechanism that allows a sender and receiver o establish a high-quality path through the underlying network and to associate datagrams with that path. • Extensible protocol. Unlike IPv4, IPv6 does not specify all possible protocol features. Instead, the designers have provided a scheme that allows a sender to add additional informaion to a datagram. The extension makes IPv6 more flexible than IPv4. 2.4.3. Discussions on IPv6 Why does IPv6 use separate extension headers? • Economy: Partitioning the datagram functionality into separate headers is economical because it saves space. Having separate headers in IPv6 makes it possible to define a large set of features without requiring each datagram header to have at least one field for each feature. • Extensibility: When adding a new feature, existing IPv6 protocol headers can remain unchanged. A new next header type can be defined as well as a new header format. • The chief advantage of placing new functionality in a new header lies in the ability to experiment with a new feature before changing all computers in the Internet. IPv6 characteristics • Practically unlimited address space • Simplification of packet header 26 Java Network Programming • Optional header fields (better support for options) • Authentication and Privacy (more Security) • More attention to type of service Plug & Play - Better Configuration optionsAdditional features of IPv6: • Network management: auto configuration o Plug-and-Play. o Automate network address renumbering o DHCP support is mandated: Every host can download their network configurations from a server at startup time o Address changes are automated ƒ Stateless ; Routers advertise prefixes that identify the subnet(s) associated with a link ; Hosts generate an “interface token” that uniquely identifies an interface on a subnet ; An address is formed by combining the two. ƒ Stateful ; Clients obtain address and / or configuration from a DHCP server ; DHCP server maintains the database and has a tight control over address assignments. • Mobile IPv6: o IPv6 Mobility is based on core features of IPv6 o The base IPv6 was designed to support Mobility o Mobility is not an “Add-on” features ƒ  All IPv6 Networks are IPv6-Mobile Ready ƒ  All IPv6 nodes are IPv6-Mobile Ready ƒ  All IPv6 LANs / Subnets are IPv6 Mobile Ready o IPv6 Neighbor Discovery and Address: Autoconfiguration allow hosts to operate in any location without any special supportNo single point of failure (Home Agent) o More Scalable : Better Performance ƒ Less traffic through Home Link ƒ Less redirection / re-routing (Traffic Optimisation)IPv6 Security: • Security features are standardized and mandated. All implementations must offer them o No Change to applications • Authentication (Packet signing) • Encryption (Data Confidentiality) 27

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.