DBI Representation and Management of Data on the Internet.

Slides:



Advertisements
Similar presentations
CSCI Java Networking1 Java Net Classes ClassDescription DatagramPacketThis class represents a datagram packet. DatagramSocketThis class represents.
Advertisements

Socket Programming By Ratnakar Kamath. What Is a Socket? Server has a socket bound to a specific port number. Client makes a connection request. Server.
1 Java Networking – Part I CS , Spring 2008/9.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Networking with Java 2: The Server Side. 2 Some Terms Mentioned Last Week TCP -Relatively slow but enables reliable byte-stream transmission UDP -Fast.
COMP1681 / SE15 Introduction to Programming
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
1 Networking in Java Representation and Management of Data on the Internet.
Client/Server In Java An Introduction to TCP/IP and Sockets.
Networking in Java Representation and Management of Data on the Internet.
Projekt współfinansowany przez Unię Europejską w ramach Europejskiego Funduszu Społecznego „Networking”
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
13-Jul-15 Sockets and URLs. 2 Sockets A socket is a low-level software device for connecting two computers together Sockets can also be used to connect.
Network Programming in Java David Meredith Aalborg University.
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
Networking in Java Representation and Management of Data on the Internet.
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
Babak Esfandiari (based on slides by Qusay Mahmoud)
SOCKET PROGRAMMING. Client/Server Communication At a basic level, network-based systems consist of a server, client, and a media for communication as.
Multicast Sockets What is a multicast socket?
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
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.
 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.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
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.
Networking with Java Socket programming. The Interweb thing Al Gore invented… Internet is a network of networks. The Internet is really people communicating.
NETWORK PROGRAMMING.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
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 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.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
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.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Network Programming. These days almost all devices.
Network Programming Communication between processes Many approaches:
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
Java 13. Networking public class SumTest {
Object-Orientated Analysis, Design and Programming
Topic: Network programming
Network Programming Introduction
MCA – 405 Elective –I (A) Java Programming & Technology
NETWORK PROGRAMMING CNET 441
Networking with Java 2.
An Introduction to TCP/IP and Sockets
Network Programming Introduction
Sockets and URLs 17-Sep-18.
Java Network Programming
„Networking”.
CSCD 330 Network Programming
Sockets and URLs 13-Nov-18.
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
Networking.
Sockets and URLs 3-Dec-18.
Java Socket Programming
Clients and Servers 19-Jul-19.
Clients and Servers 13-Sep-19.
Presentation transcript:

DBI Representation and Management of Data on the Internet

2 Networking in Java

Client-Server Model Port 80 Server application Client application

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

Servers Server - responds to connection –receives request for data –looks it up –delivers it Examples: –Web Server –Database Server –Domain Name Server

Networking Basics Communication layers: Application (HTTP, FTP, Telnet) Transport (TCP, UDF) Network (IP) Link (device, driver,…) Our programs

TCP and UDP TCP (Transmission Control Protocol) –connection-based protocol –provides a reliable flow of data between two computers UDP (User Datagram Protocol) –a protocol that sends independent packets of data, called datagrams, from one computer to another –arrival of datagrams is not gaurantees –UDP is not connection-based like TCP

How to Choose TCP or UDP Use TCP when reliability is critical: –HTTP –FTP –Telnet Use UDP when reliability is not critical: –Ping –Clock –Audio transmission –Video transmission

Making a Connection Q: How do we know where the host is located? A: By its IP address Q: There can be many applications that are in the same time connected to the same host, –for example, many browser and one search engine How do we send the right transmission to each client? A: By the Port

Host and Port Destination in the Internet is identified by host + port –a 32 bits IP-address –a 16 bits port Q: Why don’t we specify the port in a Web browser? A: Port 80 is considered the default Ports are restricted –Do not use them

Known Ports Some known ports are –20, 21: FTP –23: telnet –25: SMTP –43: whois –80: HTTP –119: NNTP

Internet Addresses InetAddress – a final class that represents Internet protocol (IP) adresses Getting the InetAdddress –getLocalHost Returns the local host –getByName(String host) For the given host name one of its IP addresses is returned –getAllByName(String host) For a given host name all its IP addresses are returned

Methods of InetAddress getHostAddress –Returns the IP address of the host –The address is in the form “%d.%d.%d.%d” getHostName –Returns the name of the host

Protocol Host Name Port Number File Name Reference Working with URLs URL (Uniform Resource Locator) - a reference (an address) to a resource on the Internet

Creating URLs The class URL is defined in the package java.net Basic constructor: URL w3c = new URL(" Relative links: –Are created from baseURL + relativeURL URL amaya = new URL(w3c, “Amaya/Amaya.html”); URL jigsaw = new URL(w3c, “Jigsaw/#Getting”);

Creating URLs (cont.) The following two are equivalent: URL dbiNotes = new URL(“ + ”~dbi/main.html#notes”); URL dbiNotes = new URL(“http”, “ 80, “~dbi/main.html#notes”); Construction of URLs can throw MalformedURLException

Why Do We Need the URL Class? The main usage of URL is for parsing URLs –getting the protocol –getting the host –getting the port –getting the file name –getting the reference An example of parsing a URL

Running the Example Java URLInfo Protocol: http Host: File name: Port: -1 Reference: null Java URLInfo Protocol: http Host: File name: /~dbi/main.html Port: 80 Reference: notes

Reading From A URL url InputStreamReader openStream BufferedReader readLine Page Content

Reading From a URL Example of reading from a given URL: UrlReader.java For reading a URL using a proxy, we do the following: Java –Dhttp.proxyHost=wwwproxy.cs.huji.ac.il –Dhttp.proxyPort=8080 UrlReader url

Reading … Java UrlReader url The content of the file

Connecting to A URL url InputStreamReader getInputStream BufferedReader URLConnection openConnection PrintWriter getOutputStream Page println readLine

Interacting with a CGI script 1.Create a URL 2.Open a connection to the URL 3.Set output capability on the URLConnection 4.Get an output stream from the connection This output stream is connected to the standard input stream of the cgi-bin script on the server 5.Write to the output stream 6.Close the output stream

HTTP connections You can create a connection to an HTTP server with an object HttpURLConnection This object extends the URLConnection object –getRequestCode –getResponseMethod –getResponceMessage Look in the Java API

URL Connection Example The next example connects to a CGI script on - a search tool is given a word to search searchWalla

Socket A socket is one end-point of a two-way communication link between two programs running on the network A socket is bound to a port number for the use of TCP (why?) Class Socket – implements the client side of the connection Class ServerSocket – implements the server side of the connection

Sockets The server has a socket that listen to a known port, e.g., Web server and port 80 The server waits (listening to the socket) till a client requests a connection A client requests a connection on the known host and port of the server Q: What should the server do so that it can serve other clients as well?

Client Requests for a Connection Port 80 Server application Client application Port 2030

Using a Socket InputStreamReader getInputStream BufferedReader readLine Page Content Socket host port

Using a Socket // Constructors (partial list) public Socket() public Socket(InetAddress address, int port); public Socket(String host, int port); // Methods (partial list) public void close(); public InetAddress getInetAddress(); public int getLocalPort(); public InputStream getInputStream(); public OutputStream getOutputStream(); public int getPort(); public String toString();

Using a Socket (client) A client: 1.Open a socket 2.Open an input stream and output stream to the socket 3.Read from and write to the stream according to the client’s protocol 4.Close the streams 5.Close the socket

Using a Socket (cont.) A server: 1.Open a socket 2.Open an input stream and output stream to the socket 3.Read from and write to the stream according to the server's protocol 4.Close the streams 5.Close the socket

A Client Example The following is a client that connects to a Time Server (port 13) and returns the curret time TimeClient

Running the TimeClient java TimeClient Tue Mar 13 12:42:

ServerSocket // Constructors (partial list) public ServerSocket(int port); public ServerSocket(int port, int count); // Methods (partial list) public Socket accept(); public void close(); public InetAddress getInetAddress(); public int getLocalPort(); public String toString();

A Server Example The following is a time server that returns the time: TimeServer Note: When the ServerSocket constructor is given port number 0, a random free port is chosen

More on Server Socket A ServerSocket 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 ServerSocket is performed by an instance of the SocketImpl class The abstract class SocketImpl is a common superclass of all classes that actually implement sockets It is used to create both client and server sockets

Server side import java.net.*; import java.io.*; // A server that says 'hello' class HelloServer { public static void main(String[] args) { int port = Integer.parseInt(args[0]); ServerSocket server = null; try { server = new ServerSocket(port); } catch (IOException ioe) { System.err.println("Couldn't run"+ "server on port "+port); return; }

Server side while(true) { try { Socket connection = server.accept(); BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream())); PrintWriter writer = new PrintWriter( new OutputStreamWriter( connection.getOutputStream())); String clientName = reader.readLine(); writer.println("Hello "+clientName); writer.flush(); } catch (IOException ioe1) {} }

Client side import java.net.*; import java.io.*; // A client of an HelloServer class HelloClient { public static void main(String[] args) { String hostname = args[0]; int port = Integer.parseInt(args[1]); Socket connection = null; try { connection = new Socket(hostname, port); } catch (IOException ioe) { System.err.println("Connection failed"); return; }

Client side try { BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream())); PrintWriter writer = new PrintWriter( new OutputStreamWriter( connection.getOutputStream())); writer.println(args[2]); // client name String reply = reader.readLine(); System.out.println("Server reply: "+reply); writer.flush(); } catch (IOException ioe1) { }

Java Net Classes ClassDescription DatagramPacketThis class represents a datagram packet. DatagramSocketThis class represents a socket for sending and receiving datagram packets. InetAddressThis class represents an Internet Protocol (IP) address. MulticastSocketThe multicast datagram socket class is useful for sending and receiving IP multicast packets. ServerSocketThis class implements server sockets. Socket This class implements client sockets (also called just "sockets"). URLA pointer to a "resource" on the World Wide Web. URLConnectionThe superclass of all classes that represent a communications link between an application and a URL.