OBJECT ORIENTED PROGRAMMING B.TECH II YR II SEMESTER(TERM 08-09) UNIT 8 PPT SLIDES TEXT BOOKS: 1. Java: the complete reference, 7th editon, Herbert schildt,

Slides:



Advertisements
Similar presentations
Network Programming Chapter 11 Lecture 6. Networks.
Advertisements

Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
Internet Programming In Java. References Java.sun.com Java552 Many of the programs shown.
COMP1681 / SE15 Introduction to Programming
Client/Server In Java An Introduction to TCP/IP and Sockets.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Process-to-Process Delivery:
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
SOCKET PROGRAMMING. Client/Server Communication At a basic level, network-based systems consist of a server, client, and a media for communication as.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
 TCP/IP is the communication protocol for the Internet  TCP/IP defines how electronic devices should be connected to the Internet, and how data should.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
DBI Representation and Management of Data on the Internet.
I. Basic Network Concepts. I.1 Networks Network Node Address Packet Protocol.
1 CSCD 330 Network Programming Winter 2015 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
Java Socket programming. Socket programming with TCP.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Web Design & Development 1 Lec - 21 Umair Javed. Web Design & Development 2 Socket Programming.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/11) Java Sockets and Simple Networking Joel Adams and Jeremy Frens.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
TCP/IP (Transmission Control Protocol / Internet Protocol)
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
Java Programming II Java Network (I) Java Programming II.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 CSCD 330 Network Programming Winter 2016 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
1 Network Communications A Brief Introduction. 2 Network Communications.
Advance Computer Programming Networking Basics – explores the java.net package which provides support for networking. – Also Called “programming for the.
Network Programming. These days almost all devices.
Network Programming Communication between processes Many approaches:
SOCKET PROGRAMMING Presented By : Divya Sharma.
Object-Orientated Analysis, Design and Programming
Network Programming in Java CS 1111 Ryan Layer May 3, 2010
MCA – 405 Elective –I (A) Java Programming & Technology
An Introduction to TCP/IP and Sockets
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
CSCD 330 Network Programming
I. Basic Network Concepts
Process-to-Process Delivery:
Transport Protocols An overview of the transport protocols of the TCP/IP protocol suite. Also, a short discussion of UDP.
Process-to-Process Delivery: UDP, TCP
CS18000: Problem Solving and Object-Oriented Programming
Exceptions and networking
Presentation transcript:

OBJECT ORIENTED PROGRAMMING B.TECH II YR II SEMESTER(TERM 08-09) UNIT 8 PPT SLIDES TEXT BOOKS: 1. Java: the complete reference, 7th editon, Herbert schildt, TMH.Understanding 2. OOP with Java, updated edition, T. Budd, pearson eduction. No. of slides:45

INDEX UNIT 9 PPT SLIDES S.NO. TOPIC LECTURE NO. PPTSLIDES 1Basics of network programming L1L1.1TO L1.7 2addresses L2L2.1 TO L2.2 3Ports L3L3.1 TO L3.2 4Sockets L 4L4.1 TO L4.3 5simple client server program L 5L5.1 TO L5.5 6Multiple clients L 6L6.1 TO L6.5 7java.net package L 7L7.1 TO L7.2 8java.util package L 8L8.1 TO L8.3 9Revision L 9

L 1.1 Basics of network programming: Overview TCP/IP java.net RMI JDBC CORBA Network OS

L 1.2 A Network Is... node –any device on the network host –a computer on the network address –computer-readable name for host host name –human-readable name for host

L 1.3 A Network Does... datagram (or “packet”) –little bundle of information –sent from one node to another protocol –roles, vocabulary, rules for communication IP –the Internet Protocol

L 1.4 TCP/IP: The Internet Protocol Physical Network Transport Layer (TCP, UDP) Internet Layer (IP) Application Layer (HTTP, FTP, SMTP)

L 1.5 TCP/UDP/IP IP –raw packets –the “Internet Layer” TCP –data stream –reliable, ordered –the “Transport Layer” UDP –user datagrams (packets) –unreliable, unordered –the “Transport Layer”

L 1.6 The Three ‘I’s internet –any IP-based network Internet –the big, famous, world-wide IP network intranet –a corporate LAN-based IP network extranet –accessing corporate data across the Internet

L 1.7 Java and Networking Built into language One of the 11 buzzwords Network ClassLoader java.net API Based on TCP/IP, the Internet Protocol

L 2.1 Addresses Every computer on the Internet has an address. An Internet address is a number that uniquely identifies each computer on the Net. There are 32 bits in an IP address, and often refer to them as a sequence of four numbers between 0 and 255 separated by dots The first few bits define which class of network, lettered A, B, C, D, or E, the address represents. Most Internet users are on a class C network, since there are over two million networks in class C.

L 2.2 IP Addresses The first byte of a class C network is between 192 and 224, with the last byte actually identifying an individual computer among the 256 allowed on a single class C network. IP Address: identifies a host DNS: converts host names / domain names into IP addresses.

L 3.1 Ports Port: a meeting place on a host 1.one service per port = well-known services = experimental services, temporary

L 3.2 Well-Known Ports 20,21: FTP 23: telnet 25: SMTP 43: whois 80: HTTP 119: NNTP 1099: RMI

L 4.1 Sockets A network socket is a lot like an electrical socket. Socket: a two-way connection Internet Protocol (IP) is a low-level routing protocol that breaks data into small packets and sends them to an address across a network, which does not guarantee to deliver said packets to the destination. 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 your data. A third protocol, User Datagram Protocol (UDP), sits next to TCP and can be used directly to support fast, connectionless, unreliable transport of packets.

L 4.2 The Socket Class Socket(String host, int port) InputStream getInputStream() OutputStream getOutputStream() void close() Socket s = new Socket(“ 90);

L 4.3 Client Sockets and Ports port 13 port 80 Time Service Web Service Socket Server Socket

L 5.1 Client-Server Client - initiates connection –retrieves data, –displays data, –responds to user input, –requests more data Examples: –Web Browser –Chat Program –PC accessing files

L 5.2 simple client server program-client /** Client program using TCP */ public class Tclient { final static String serverIPname = “starwave.com";// server IP name final static int serverPort = 3456;// server port number public static void main(String args[]) { java.net.Socket sock = null;// Socket object for communicating java.io.PrintWriterpw = null;// socket output to server java.io.BufferedReader br = null;// socket input from server try { sock = new java.net.Socket(serverIPname,serverPort);// create socket and connect pw = new java.io.PrintWriter(sock.getOutputStream(), true); // create reader and writer br = new java.io.BufferedReader(new java.io.InputStreamReader(sock.getInputStream())); System.out.println("Connected to Server");

L 5.3 pw.println("Message from the client");// send msg to the server System.out.println("Sent message to server"); String answer = br.readLine();// get data from the server System.out.println("Response from the server >" + answer); pw.close(); // close everything br.close(); sock.close(); } catch (Throwable e) { System.out.println("Error " + e.getMessage()); e.printStackTrace(); }

L 5.4 Server program /** Server program using TCP */ public class Tserver { final staticintserverPort = 3456; // server port number public static void main(String args[]) { java.net.ServerSocket sock = null; // original server socket java.net.Socket clientSocket = null;// //socket created by accept java.io.PrintWriter pw = null;// //socket output stream java.io.BufferedReaderbr = null; // socket input stream try { sock = new java.net.ServerSocket(serverPort); // create socket and bind to port System.out.println("waiting for client to connect"); clientSocket = sock.accept();

L 5.5 // wait for client to connect System.out.println("client has connected"); pw = new java.io.PrintWriter(clientSocket.getOutputStream(),true); br = new java.io.BufferedReader( new java.io.InputStreamReader(clientSocket.getInputStream())); String msg = br.readLine(); // read msg from client System.out.println("Message from the client >" + msg); pw.println("Got it!");// send msg to client pw.close(); // close everything br.close(); clientSocket.close(); sock.close(); } catch (Throwable e) { System.out.println("Error " + e.getMessage()); e.printStackTrace(); }

L 6.1 Multiple Clients Multiple clients can connect to the same port on the server at the same time. Incoming data is distinguished by the port to which it is addressed and the client host and port from which it came. The server can tell for which service (like http or ftp) the data is intended by inspecting the port. It can tell which open socket on that service the data is intended for by looking at the client address and port stored with the data.

L 6.2 Queueing Incoming connections are stored in a queue until the server can accept them. On most systems the default queue length is between 5 and 50. Once the queue fills up further incoming connections are refused until space in the queue opens up.

L 6.3 The java.net.ServerSocket Class The java.net.ServerSocket class represents a server socket. A ServerSocket object is constructed on a particular local port. Then it calls accept() to listen for incoming connections. accept() blocks until a connection is detected. Then accept() returns a java.net.Socket object that performs the actual communication with the client.

L 6.4 Constructors There are three constructors that specify the port to bind to, the queue length for incoming connections, and the IP address to bind to: public ServerSocket(int port) throws IOException public ServerSocket(int port, int backlog) throws IOException public ServerSocket(int port, int backlog, InetAddress networkInterface) throws IOException

L 6.5 Constructing Server Sockets specify the port number to listen : try { ServerSocket ss = new ServerSocket(80); } catch (IOException e) { System.err.println(e); }

L 7.1 java.net package The classes in java.net package are : JarURLConnection (Java 2) URLConnection DatagramSocketImplServerSocket URLDecoder (Java 2)HttpURLConnection SocketURLEncoder InetAddressSocketImpl URLStreamHandlerSocketPermission ContentHandlerMulticastSocket URLDatagramPacket NetPermissionURLClassLoader (Java 2) DatagramSocketPasswordAuthentication(Java 2) Authenticator (Java 2)

L 7.2 The java.net package's interfaces are 1.ContentHandlerFactory 2.SocketImplFactory 3.URLStreamHandlerFactory 4.FileNameMap 5.SocketOptions

L 8.1 java.util package The java.util package defines the following classes: 1. AbstractCollection (Java2) 2.EventObject 3.PropertyResourceBundle 4.AbstractList (Java 2) 5.GregorianCalendar 6.Random 7.AbstractMap (Java 2) 8.HashMap(Java 2) 9.ResourceBundle 10.AbstractSequentialList(Java 2) 11.HashSet (Java2) 12.SimpleTimeZone 13.AbstractSet (Java 2) 14.Hashtable 15.Stack

L ArrayList (Java 2) 17.LinkedList(Java 2) 18.StringTokenizer 19.Arrays (Java 2) 20.ListResourceBundle 21.TimeZone 22.BitSet 23.Locale 24.TreeMap (Java 2) 25.Calendar 26.Observable 27.TreeSet (Java 2) 28.Collections (Java 2) 29.Properties 30.Vector 31.Date 32.PropertyPermission(Java 2) 33.WeakHashMap (Java 2) 34.Dictionary

L 8.3 java.util defines the following interfaces. 1.Collection (Java 2) 2.List (Java 2) 3.Observer 4.Comparator (Java 2) 5.ListIterator(Java 2) 6.Set (Java 2) 7.Enumeration 8.Map (Java 2) 9.SortedMap (Java 2) 10.EventListener 11.Map.Entry(Java 2) 12.SortedSet (Java 2) 13.Iterator (Java 2)