Computer Networks Network - A system of computers interconnected in order to share information. Data transmission - consists of sending and receiving streams of zeros and ones along the network connection LAN - a local computer network for communication between computers to create a communication system between offices (local area network) Internet - A worldwide collection of networks, routing equipment, and computers
Most networks use a common set of rules, or a protocol, to define how the parties will interact with each other Local area network protocols o Microsoft Networking o Novell NetWare o AppleTalk Protocol for connecting local area networks o Internet Protocol (IP)
Most networks use a common set of rules, or a protocol, to define how the parties will interact with each other Two types of data are transmitted along network: Application data Application data – consists of the information one computer wants to send to another Network protocol data Network protocol data – describes how to reach the intended computer – describes how to check for errors in the transmission
Overview: Internet Transmission A is your home computerA is your home computer It is connected to an Internet Service Provider (ISP)It is connected to an Internet Service Provider (ISP) The ISP is connected to an Internet Access PointThe ISP is connected to an Internet Access Point B is on an local area network at XYZ Computers.B is on an local area network at XYZ Computers. XYZ has its own Internet Access PointXYZ has its own Internet Access Point The Internet Access Points are connected by a complex collection of pathways (the Internet)The Internet Access Points are connected by a complex collection of pathways (the Internet) Over these pathways a message sent from one access point can eventually reach any access pointOver these pathways a message sent from one access point can eventually reach any access point A number of protocols work to ensure that this transmission is successfulA number of protocols work to ensure that this transmission is successful
Two Computers Communicating across the Internet
Packets IP (Internet Protocol) breaks large chunks of data up into more manageable packets Each packet is delivered separately Each packet in a larger transmission may be sent by a different route and therefore must contain the destination address Packets are also numbered, so they can be reassembled by the recipient
Data must be marked with a destination address Data must be marked with a destination address in order to arrive at the correct destination in order to arrive at the correct destination The protocol being used determines the format of that destination address. In IP, addresses are denoted by a sequence of four numbers The protocol being used determines the format of that destination address. In IP, addresses are denoted by a sequence of four numbers o Each is one byte (between 0 and 255) o Each is one byte (between 0 and 255) For example: For example: To send data to B, A includes B’s internet address in the protocol portion of the transmission To send data to B, A includes B’s internet address in the protocol portion of the transmission IP Address
Domain Naming Service In addition to an IP address, computers can have an easy-to-remenber domain name oFor example, java.sun.com A service called a Domain Naming Service (DNS) translates from domain name to Internet address When a computer wishes to request data from another, and the domain name is known: It asks the DNS for the numeric Internet Address oIt includes the numeric address with the request for data
Port Numbers One computer can offer multiple services over the Internet One computer can offer multiple services over the Internet eg. Web server eg. Web server server server When data is sent, that computer needs to know which program to receive the data. IP uses port numbers ( When data is sent, that computer needs to know which program to receive the data. IP uses port numbers ( 0 thru 65,535 ) for this. The sending program must know the port number of the receiving program This number is also included in the transmitted data. previousprevious | start | nextstartnext previousprevious | start | nextstartnext
Transmission Control Protocol (TCP) Internet Protocol (IP) does not notify the sender if data is lost or garbled. Internet Protocol (IP) does not notify the sender if data is lost or garbled. This is the job of a higher level protocol Transmission Control Protocol (TCP) This is the job of a higher level protocol Transmission Control Protocol (TCP) The most commonly used Internet services use TCP with IP (TCP/IP) The most commonly used Internet services use TCP with IP (TCP/IP) TCP will attempt to deliver data, and try again if there are failures. The sender will be notified if the attempt was successful or not). TCP will attempt to deliver data, and try again if there are failures. The sender will be notified if the attempt was successful or not).
Contents of TCP Packet The Internet address of the recipient The port number of the recipient Internet address of the sender The port number of the sender TCP/IP mechanism establishes an Internet connection between two ports on two computers
yet another protocol……………….. Each Internet application has its own application protocol This application protocol describes how data for that application are transmitted The application protocol used to transport resources available on the WWW is Hypertext Transfer Protocol (HTTP) HTTP uses a Uniform Resource Locator (URL)to specify a resource. For example:
Browser Steps You type into the browser's address The browser examines the part of the URL between the double slash and the first single slash o In this case: java.sun.com o This identifies the computer to which you want to connect o Because it contains letters, this part of the URL is a domain name The browser sends a request to a DNS server to obtain the Internet address of the computer with the domain name java.sun.com. This is then used when sending the request.
Browser Steps From the http: prefix to the URL, the browser decides that the protocol you want to use is HTTP ( HTTP uses port 80 by default) ( HTTP uses port 80 by default) The browser establishes a TCP/IP connection to port 80 at the Internet address that was provided by DNS The browser deduces from the /index.html that you want to see the file /index.html It sends this request formatted as an HTTP command through the established connection
Browser Steps The web server running on destination computer receives the request It decodes the request It fetches the file /index.html and sends the file back to the browser The browser displays the contents of the file Since this file is an HTML file, the browser decodes the HTML codes into fonts, paragraphs etc. If the file contains images, the browser makes more GET requests through the same connection
java.net As we have seen, networks are functional due to a vast layering of protocols. Most of these protocols are contained in the software that runs on general purpose computers. Some of the lower level protocols are implemented in the software that runs on the the network routers. Most of these protocols are contained in the software that runs on general purpose computers. Some of the lower level protocols are implemented in the software that runs on the the network routers. The java.net package provides a powerful set of classes that supports network programming easily -- encapsulating as much of the network protocol detail as you wish
The java.URL and java.URLConnection classes are for creating and manipulating URL’s -- working at the application protocol level. The Socket and ServerSocket classes allow you to communicate over TCP/IP sockets, where a socket is an abstraction of the end point of a connection). This is quite similar to read and writing files, once a connection is established. The DatagramPacket and DatagramSocket classes provide lower level services which are based on Internet packets themselves.
URL Class The URL class models a Uniform Resource Locator.. the directions to a resource which resides on the Internet. A URL object can be constructed in a variety of ways, including: URL (String specification) URL (String protocol, String host, int port, String file) * Both of these constructors throw a MalformedURLException if the parameters are not semantically correct. However, No validation of parameters is done by this constructor
Using a URL object Once you have a URL instance, it can be used to download the resource to which points. There are different ways to do this: * openStream() opens a connection to this URL and returns an InputStream object for reading from that connection * openConnection() returns a URLConnection object that represents an open connection to the resource * use another API method, passing the URL object eg) Applet class provides Image getImage(URL) Toolkit class provides getImage(URL) ImageIcon class provides ImageIcon(URL)
URL Exercises *Write a Java GUI which displays a label on a panel. The label displays a picture. The picture resides at: *Write a Java GUI which displays a picture on a panel. The picture resides at: *Write a Java application which makes a copy of the file NNN.txt in the current folder. NNN.txt resides at: (Hint: Create a stream, and then treat the resource as a file, which it is!!)