OBJECT ORIENTED PROGRAMMING

Similar documents
Networking and Security

Introduction to Java.net Package. CGS 3416 Java for Non Majors

Interprocess Communication

AJP: Chapter 2 Networking: 18 marks

Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub

Advanced Java Programming. Networking

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

Networking Basics. network communication.

JAVA SOCKET PROGRAMMING

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Chapter 11. Application-Layer Elements Ports

Outline. Inter-Process Communication. IPC across machines: Problems. CSCI 4061 Introduction to Operating Systems

CSCD 330 Network Programming Spring 2018

CSCD 330 Network Programming

ECE 333: Introduction to Communication Networks Fall 2002

The Transmission Control Protocol (TCP)

ECE 333: Introduction to Communication Networks Fall 2001

Communication Paradigms

Distributed Systems Recitation 2. Tamim Jabban

Chapter 7. Local Area Network Communications Protocols

Data Communication & Computer Networks MCQ S

TCP/IP Overview. Basic Networking Concepts. 09/14/11 Basic TCP/IP Networking 1

CSC 4900 Computer Networks: P2P and Sockets

Networking with java (socket programming) a brief study

System Programming. Introduction to computer networks

Introduction to TCP/IP

Networking and Internetworking 1

CCNA 1 v3.11 Module 11 TCP/IP Transport and Application Layers

TCP/IP THE TCP/IP ARCHITECTURE

CPSC156a: The Internet Co-Evolution of Technology and Society. Lecture 4: September 16, 2003 Internet Layers and the Web

Session 2. Background. Lecture Objectives

Introduction to Socket Programming

C18: Network Fundamentals and Reliable Sockets

Network Programming. Introduction to Sockets. Dr. Thaier Hayajneh. Process Layer. Network Layer. Berkeley API

Concept Questions Demonstrate your knowledge of these concepts by answering the following questions in the space provided.

OSI Transport Layer. Network Fundamentals Chapter 4. Version Cisco Systems, Inc. All rights reserved. Cisco Public 1

PLEASE READ CAREFULLY BEFORE YOU START

Distributed Systems Recitation 2. Tamim Jabban

Connecting to a Server Implementing Servers Making URL Connections Advanced Socket Programming

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

TCP/IP stack is the family of protocols that rule the current internet. While other protocols are also used in computer networks, TCP/IP is by far

IEMS 5780 / IERG 4080 Building and Deploying Scalable Machine Learning Services

C19: User Datagram and Multicast

SC/CSE 3213 Winter Sebastian Magierowski York University CSE 3213, W13 L8: TCP/IP. Outline. Forwarding over network and data link layers

Chapter 9: UDP sockets & address conversion function

CCNA Exploration Network Fundamentals. Chapter 3 Application Layer Functionality and Protocols

Business Data Networks and Security 10th Edition by Panko Test Bank

CN1047 INTRODUCTION TO COMPUTER NETWORKING CHAPTER 6 OSI MODEL TRANSPORT LAYER

Unix Network Programming

Defining Networks with the OSI Model. Module 2

CSc 450/550 Computer Networks Network Architectures & Client-Server Model

The Internet Advanced Research Projects Agency Network (ARPANET) How the Internet Works Transport Control Protocol (TCP)

Java Networking (sockets)

CS321: Computer Networks FTP, TELNET, SSH

Internet Protocol. Chapter 5 Protocol Layering. Juho Kim Graduate School of Information & Technology Sogang University

MODULE: NETWORKS MODULE CODE: CAN1102C. Duration: 2 Hours 15 Mins. Instructions to Candidates:

JAVA - NETWORKING (SOCKET PROGRAMMING)

Context. Distributed Systems: Sockets Programming. Alberto Bosio, Associate Professor UM Microelectronic Departement

Sockets 15H2. Inshik Song

Socket Programming(TCP & UDP) Sanjay Chakraborty

CS 351 Design of Large Programs Java and Socket Communication

Configure Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) Service Settings on a Switch

Different Layers Lecture 21

TRANSMISSION CONTROL PROTOCOL (TCP) FUNDAMENTALS AND GENERAL OPERATION

CCNA Exploration Network Fundamentals. Chapter 04 OSI Transport Layer

PLEASE READ CAREFULLY BEFORE YOU START

PLEASE READ CAREFULLY BEFORE YOU START

Chapter 2 Network Models 2.1

OSI Transport Layer. objectives

The Internet. Tim Capes. November 7, 2011

PLEASE READ CAREFULLY BEFORE YOU START

Network Protocols - Revision

Lecture 2. Outline. Layering and Protocols. Network Architecture. Layering and Protocols. Layering and Protocols. Chapter 1 - Foundation

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt

Network+ Guide to Networks 6 th Edition. Chapter 4 Introduction to TCP/IP Protocols

Network and Security: Introduction

ECS-503 Object Oriented Techniques

SERVER/CLIENT NETWORKING AT JAVA PLATFORM

Hands-On Ethical Hacking and Network Defense

Chapter 11: Wide-Area Networks and the Internet

Computer Communication & Networks / Data Communication & Computer Networks Week # 03

Application Layer Introduction; HTTP; FTP

Networking and the Web Reminder: Next Quiz on 4/15

Chapter 7 Transport Layer. 7.0 Introduction 7.1 Transport Layer Protocols 7.2 TCP and UDP 7.3 Summary

Chapter 2 - Part 1. The TCP/IP Protocol: The Language of the Internet

ECE 650 Systems Programming & Engineering. Spring 2018

TSIN02 - Internetworking

Joseph Faber Wonderful Talking Machine (1845)

How the Web Works. Chapter 1. Modified by Marissa Schmidt Pearson

CSCD 330 Network Programming Spring 2018

CSC 546: Client/Server Fundamentals. Fall Major client/server protocols

Practical Session #09 Exceptions & Networking. Tom Mahler

CCNA 1 Chapter 7 v5.0 Exam Answers 2013

Set of IP routers. Set of IP routers. Set of IP routers. Set of IP routers

CSCD 330 Network Programming Winter 2019

Interprocess Communication Mechanisms

Objectives. Connecting with Computer Science 2

shared storage These mechanisms have already been covered. examples: shared virtual memory message based signals

Network Reference Models

Guide to Networking Essentials, 6 th Edition. Chapter 5: Network Protocols

Transcription:

1 OBJECT ORIENTED PROGRAMMING Lecture 14 Networking Basics

Outline 2 Networking Basics Socket IP Address DNS Client/Server Networking Class & Interface URL Demonstrating URL

Networking 3 Java is practically a synonym for Internet programming. There are a number of reasons for this, not the least of which is its ability to generate secure, cross-platform, portable code. Classes used for network programming are the classes defined in the java.net package. They provide an easy-to-use means by which programmers of all skill levels can access network resources.

Networking Basics- Socket 4 There are some key networking concepts and terms, the concept of a socket. A socket identifies an endpoint in a network. Sockets are at the foundation of modern networking because a socket allows a single computer to serve many different clients at once, as well as to serve many different types of information. This is accomplished through the use of a port, which is a numbered socket on a particular machine. A server process is said to listen to a port until a client connects to it. A server is allowed to accept multiple clients connected to the same port number, although each session is unique. To manage multiple client connections, a server process must be multithreaded or have some other means of multiplexing the simultaneous I/O.

Networking Basics - Protocol 5 Socket communication takes place via a protocol. Internet Protocol (IP) is a low-level routing protocol that breaks data into small packets and sends them to an address across a network. Transmission Control Protocol (TCP) is a higher-level protocol that manages to robustly string together these packets, sorting and retransmitting them as necessary to reliably transmit data. User Datagram Protocol (UDP), sits next to TCP and can be used directly to support fast, connectionless, unreliable transport of packets. Once a connection has been established, a higher-level protocol ensues, which is dependent on which port you are using. TCP/IP reserves the lower 1,024 ports for specific protocols.

Networking Basics - Protocol 6 Port number 21 is for FTP; 23 is for Telnet; 25 is for e-mail; 43 is for whois; 79 is for finger; 80 is for HTTP; 119 is for netnews and the list goes on. For example, HTTP is the protocol that web browsers and servers use to transfer hypertext pages and images. It is a quite simple protocol for a basic page-browsing web server. How HTTP works? When a client requests a file from an HTTP server, an action known as a hit, it simply sends the name of the file in a special format to a predefined port and reads back the contents of the file. The server also responds with a status code to tell the client whether or not the request can be fulfilled and why. A key component of the Internet is the address, every computer on the Internet has one. An Internet address is a number that uniquely identifies each computer on the Net. Originally, all Internet addresses consisted of 32-bit values, organized as four 8-bit values, for IPv4 (Internet Protocol, version 4) type, or 128-bit value, organized into eight 16-bit chunks for IPv6.

Networking Basics - DNS 7 Domain Name: Like IP address describe a network hierarchy, the name of an Internet address, called its domain name, describes a machine s location in a name space. For example, www.osborne.com is in the COM domain (reserved for U.S. commercial sites); it is called osborne (after the company name), and www identifies the server for web requests. Domain Naming Service (DNS): is used to map an Internet domain name is mapped to an IP address. This enables users to work with domain names, but the Internet operates on IP addresses.

Java.net classes 8

Java.net Interfaces 9

InetAddress class 10 The InetAddress class is used to encapsulate both the numerical IP address and the domain name for that address. You interact with this class by using the name of an IP host, which is more convenient and understandable than its IP address. The InetAddress can handle both IPv4 and IPv6 addresses.

InetAddress- Factory Methods 11 The InetAddress class has no visible constructors. To create an InetAddress object, you have to use one of the available factory methods. Factory methods are merely a convention whereby static methods in a class return an instance of that class. Three commonly used InetAddress factory methods are shown here:

InetAddress- Factory Methods 12 getlocalhost( ) method simply returns the InetAddress object that represents the local host. getbyname( ) method returns an InetAddress for a host name passed to it. If these methods are unable to resolve the host name, they throw UnknownHostException. getbyaddress( ), which takes an IP address and returns an InetAddress object. Either an IPv4 or an IPv6 address can be used.

Example Using InetAddress 13

InetAddress- Instance Methods 14 The InetAddress class has several other methods.

Client /Server 15 Client/server describes the relationship between two computer programs in which one program, the client, makes a service request from another program, the server, which fulfills the request. In a network, the client/server model provides a convenient way to interconnect programs that are distributed efficiently across different locations. For example, to check your bank account from your computer, a client program in your computer forwards your request to a server program at the bank. That program may in turn forward the request to its own client program that sends a request to a database server at another bank computer to retrieve your account balance. The balance is returned back to the bank data client, which in turn serves it back to the client in your personal computer, which displays the information for you.

16 TCP/IP sockets are used to implement reliable, bidirectional, persistent, point-to-point, stream-based connections between hosts on the Internet. A socket can be used to connect Java s I/O system to other programs that may reside either on the local machine or on any other machine on the Internet. There are two kinds of TCP sockets in Java. One is for servers, and the other is for clients. The ServerSocket class for servers: is designed to be a listener, which waits for clients to connect before doing anything. The Socket class for clients, it is designed to connect to server sockets and initiate protocol exchanges.

How to create TCP/IP Client Socket 17 The creation of a Socket object implicitly establishes a connection between the client and server. There are two constructors are used to create client sockets. Socket defines several instance methods. For example, a Socket can be examined at any time for the address and port information associated with it.

How to create TCP/IP Client Socket 18 You can gain access to the input and output streams associated with a Socket by use of the getinputstream( ) and getouptutstream( ) methods, as shown here. Each can throw an IOException if the socket has been invalidated by a loss of connection. isconnected( ), which returns true if the socket is connected to a server. isbound( ), which returns true if the socket is bound to an address. isclosed( ), which returns true if the socket is closed.

TCP/IP Client Sockets example 19 The following program provides a simple Socket example. It opens a connection to a whois port (port 43) on the InterNIC server, sends the command-line argument down the socket, and then prints the data that is returned. InterNIC will try to look up the argument as a registered Internet domain name, and then send back the IP address and contact information for that site.

20

Output 21

Example Comments 22 Here is how the program works. First, a Socket is constructed that specifies the host name "internic.net" and the port number 43. Internic.net is the InterNIC web site that handles whois requests. Port 43 is the whois port. Next, both input and output streams are opened on the socket. Then, a string is constructed that contains the name of the web site you want to obtain information about. In this case, if no web site is specified on the command line, then "osborne.com" is used. The string is converted into a byte array and then sent out of the socket. The response is read by inputting from the socket, and the results are displayed.

URL 23 The preceding example was rather obscure because the modern Internet is not about the older protocols such as whois, finger, and FTP. It is about WWW, the World Wide Web. The Web is a loose collection of higher-level protocols and file formats, all unified in a web browser. One of the most important aspects of the Web is that Tim Berners-Lee devised a scalable way to locate all of the resources of the Net. The Uniform Resource Locator (URL) provides a reasonably intelligible form to uniquely identify or address information on the Internet. URLs are ubiquitous; every browser uses them to identify information on the Web. Within Java s network class library, the URL class provides a simple, concise API to access information across the Internet using URLs.

URL 24 All URLs share the same basic format, although some variation is allowed. For example: http://www.osborne.com/ and http://www.osborne.com:80/index.htm. An URL specification is based on four components. 1. The protocol to use, separated from the rest of the locator by a colon (:). Common protocols are HTTP, FTP, gopher, and file, although these days almost everything is being done via HTTP (in fact, most browsers will proceed correctly if you leave off the http:// from your URL specification). 2. The host name or IP address of the host to use; this is delimited on the left by double slashes (//) and on the right by a slash (/) or optionally a colon (:). 3. The port number, is an optional parameter, delimited on the left from the host name by a colon (:) and on the right by a slash (/). (It defaults to port 80, the predefined HTTP port; thus, :80 is redundant.) 4. The actual file path. Most HTTP servers will append a file named index.html or index.htm to URLs that refer directly to a directory resource. Thus, http://www.osborne.com/ is the same as http://www.osborne.com/ index.htm.

URL 25 Java s URL class has several constructors; each can throw a MalformedURLException. One commonly used form specifies the URL with a string that is identical to what you see displayed in a browser: URL(String urlspecifier) throws MalformedURLException The next two forms of the constructor allow you to break up the URL into its component parts: URL(String protocolname, String hostname, int port, String path) throws MalformedURLException URL(String protocolname, String hostname, String path) throws MalformedURLException

The following example creates a URL to Osborne s download page and then examines its properties: 26 //Notice that the port is 1; this means that a port was not explicitly set.

Example Comments 27