1 / 67

Networking Part I

Networking Part I. May 21, 2014. Administrivia: Introductions. Dennis Mumaugh Undergraduate: BSEE - University of California, Berkeley MS Computer Science - University of Maryland Ph.D. Studies - University of Maryland Teaching at DePaul since September 2000 Work

colleen
Download Presentation

Networking Part I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Networking Part I May 21, 2014 JDP Networking Part I

  2. Administrivia: Introductions Dennis Mumaugh Undergraduate: BSEE - University of California, Berkeley MS Computer Science - University of Maryland Ph.D. Studies - University of Maryland Teaching at DePaul since September 2000 Work Senior Engineer - National Security Agency ARPANet Pioneer, Unix™ Technology Transfer Member of the Technical Staff - Bell Labs/Lucent Technologies Unix Development - Current Engineering IS&R Systems - Knowledge Based Systems Software Tools and OO Technology Interests Operating Systems and System Programming Software Productivity, Compilers and Software Metrics Software Engineering JDP Networking Part I

  3. Administrivia: contact details • Contact Information: • Email: dmumaugh@cdm.depaul.edu • Phone: 630-983-1221 (10:00 am - 11:00 pm) except just before classes • Office: CDM 429 • Office Hours: Monday, 4:00-5:30 JDP Networking Part I

  4. Administrivia: reading materials • Course home page: http://condor.depaul.edu/dmumaugh/JDPcontains reading assignments, lectures, homework, pointers to API documentation, more reading material, sample source code • Textbooks • Core Java, Volume I – Fundamentals, Eighth Edition, Cay S. Horstmann and Gary Cornell, ISBN: 978-0132354769 • Other books you may want to read • Core Java, Volume II – Advanced Features, Eighth Edition, Cay S. Horstmann and Gary Cornell, ISBN:978-0132354790 • Java Network Programming, Harold, Elliotte Rusty, O'Reilly, 3rd edition, 2004, ISBN 0-596-00217-3 • Fundamental Networking in Java, Pitt, Esmond, Springer, 2006, ISBN 1-84628-030-3 JDP Networking Part I

  5. Thought for the Day (In 1970) The original Internet (called the ARPANet) was intended to be used to provide distributed and collaborative systems. It was actually used primarily for sending email. JDP Networking Part I

  6. This Lecture • Topic: Network programming • Reading: • Harold: Chapters 2-3, 9 and 10; pp. 525-542 • Core Java, Vol. 2: pp. 1-64, 169-217 • Core Java, Vol. 1: pp. 516-539 • Sun's [really Oracle] API javadoc documentation on the Socket and ServerSocket classes. • Technology Briefs (see class page for URL) • TCP/IP • HTTP • Article on “Reading Data from the Internet” JDP Networking Part I

  7. Java Networking JDP Networking Part I

  8. Introduction to Networking • What is a network? Why do we care? • Need to understand what we are working with. • Terms • LAN • WAN • Internet JDP Networking Part I

  9. Networks JDP Networking Part I

  10. Networks JDP Networking Part I

  11. Introduction to Networking • What is a hub? • A switch? • A router? • A WAP? JDP Networking Part I

  12. Networks RouterFirewall RouterFirewall JDP Networking Part I

  13. The Internet and network programming What is the Internet? • Hosts • Interfaces • Routers • LANS • Gateways • Protocols • SOFTWARE JDP Networking Part I

  14. Network Programming JDP Networking Part I

  15. The Notion of an Internet Protocol • How is it possible to send bits across incompatible LANs and WANs? • Solution: protocol software running on each host and router smoothes out the differences between the different networks. • Implements an internet protocol (i.e., set of rules) that governs how hosts and routers should cooperate when they transfer data from network to network. • TCP/IP is the protocol for the global IP Internet. JDP Networking Part I

  16. What Does an Internet Protocol Do? • Provides a naming scheme • An internet protocol defines a uniform format for host addresses. • Each host (and router) is assigned at least one of these internet addresses that uniquely identifies it. • Provides a delivery mechanism • An internet protocol defines a standard transfer unit (packet) • Packet consists of headerand payload • Header: contains info such as packet size, source and destination addresses. • Payload: contains data bits sent from source host. JDP Networking Part I

  17. Global IP Internet • Most famous example of an internet. • Based on the TCP/IP protocol family • Level 3 - IP (Internet protocol) : • Provides basic naming scheme and unreliable delivery capability of packets (datagrams) from host-to-host. • Level 4 - UDP (User Datagram Protocol) • Uses IP to provide unreliable datagram delivery from process-to-process. • Level 4 - TCP (Transmission Control Protocol) • Uses IP to provide reliable byte streams from process-to-process over connections. • Accessed via a mix of Java file I/O and functions from the sockets interface. JDP Networking Part I

  18. Transferring Data Over an internet Host A Host B client server (1) (8) data data protocol software protocol software internet packet (7) data PH (2) data PH (3) LAN1 adapter LAN2 adapter FH2 data PH FH1 (6) data PH Router LAN1 frame LAN1 adapter LAN2 adapter LAN1 LAN2 LAN2 frame (4) data PH FH1 data PH FH2 (5) protocol software JDP Networking Part I

  19. Introduction to Network Programming • What is IP? • What is a firewall? • A proxy? • Network Address Translation? • What is an RFC? • Request For Comment JDP Networking Part I

  20. Introduction to Network Programming • What is a lossy network? • What is an unordered network? TCP versus UDP • What is TCP? What does it provide? • TCP (Transmission Control Protocol) guarantees that all segments will arrive at the destination and in the right order. (It makes no guarantees about how long it will take.) • What is UDP? Why use it? • UDP (User Datagram Protocol) makes no such guarantees. So UDP is mostly like IP, but with the extension that it gets data from source process to destination process. UDP is used where performance is needed and occasional loss of data is not critical. E.g. audio and video streaming, short protocols such as DNS, name services, etc. • UPD is a faster protocol. It has less overhead. But the trade off is loss and unordered. JDP Networking Part I

  21. Introduction to Network Programming Questions to answer: • What is the client-server model? • What is the difference between the client and the server? • What are example client/server pairs? • Are there other models? JDP Networking Part I

  22. Client-Server Model • Every network application is based on the client-server model: • A server process and one or more clientprocesses • Server manages some resource. • Server providesservice by manipulating resource for clients. 1. Client sends request Client process Server process Resource 4. Client handles response 2. Server handles request 3. Server sends response Note: clients and servers are processes running on hosts (can be the same or different hosts). JDP Networking Part I

  23. Clients • Examples of client programs • Web browsers, ftp, telnet, ssh • How does a client find the server? • The IP address in the server socket address identifies the host (more precisely, an adapter on the host) • The (well-known) port in the server socket address identifies the service, and thus implicitly identifies the server process that performs that service. • Examples of well known ports • Port 7: Echo server • Port 23: Telnet server • Port 25: Mail server • Port 80: Web server JDP Networking Part I

  24. Servers • Servers are long-running processes (daemons). • Created at boot-time (typically) by the init process (process 1) • Run continuously until the machine is turned off. • Each server waits for requests to arrive on a well-known port associated with a particular service. • Port 7: echo server • Port 23: telnet server • Port 25: mail server • Port 80: HTTP server • A machine that runs a server process is also often referred to as a “server.” JDP Networking Part I

  25. Server Examples • Web server (port 80) • Resource: files/compute cycles (CGI programs) • Service: retrieves files and runs CGI programs on behalf of the client • FTP server (20, 21) • Resource: files • Service: stores and retrieve files • Telnet server (23) • Resource: terminal • Service: proxies a terminal on the server machine • Mail server (25) • Resource: email “spool” file • Service: stores mail messages in spool file See /etc/services for a comprehensive list of the services available on a Linux machine. JDP Networking Part I

  26. A Programmer’s View of the Internet • Hosts are mapped to a set of 32-bit IP addresses. • 128.2.203.179 • The set of IP addresses is mapped to a set of identifiers called Internet domain names. [A host name]. • 128.2.203.179 is mapped to www.cs.cmu.edu • How do hostnames get matched to IP addresses? • What is /etc/hosts? • What is a DNS? • A process on one Internet host can communicate with a process on another Internet host over a connection. • What is special about addresses 127.0.0.*? • Each host has a locally defined domain name localhost which always maps to the loopback address127.0.0.1 • 192.168.*.*? (See notes page for answer). JDP Networking Part I

  27. Internet Connections • Clients and servers communicate by sending streams of bytes over connections: • Point-to-point, full-duplex (2-way communication), and reliable. • A socket is an endpoint of a connection • Socket address is an IPaddress:port pair • A port is a 16-bit integer that identifies a process: • Ephemeral port: Assigned automatically on client when client makes a connection request • Well-known port: Associated with some service provided by a server (e.g., port 80 is associated with Web servers) • A connection is uniquely identified by the socket addresses of its endpoints (socket pair) • (cliaddr:cliport, servaddr:servport) JDP Networking Part I

  28. Using Ports to Identify Services Server host 128.2.194.242 Client host Web server (port 80) Service request for 128.2.194.242:80 (i.e., the Web server) Kernel Client Echo server (port 7) Web server (port 80) Service request for 128.2.194.242:7 (i.e., the echo server) Kernel Client Echo server (port 7) JDP Networking Part I

  29. Introduction to Network Programming • Are there other models? • Peer-to-peer [Napster] • Three tiered systems • Service Oriented Architecture • CORBA • Distributed Services JDP Networking Part I

  30. Domain Naming System (DNS) unnamed root mil edu gov com First-level domain names Second-level domain names mit cmu berkeley amazon Third-level domain names cs ece www 208.216.181.15 • The Internet maintains a mapping between IP addresses and domain names in a huge worldwide distributed database called DNS. JDP Networking Part I

  31. Querying DNS from the Command Line • Domain Information Groper (dig) provides a scriptable command line interface to DNS. linux> dig +short kittyhawk.cmcl.cs.cmu.edu 128.2.194.242 linux> dig +short -x 128.2.194.242 KITTYHAWK.CMCL.CS.CMU.EDU. linux> dig +short aol.com 205.188.145.215 205.188.160.121 64.12.149.24 64.12.187.25 linux> dig +short -x 64.12.187.25 aol-v5.websys.aol.com. JDP Networking Part I

  32. The Eight Fallacies of Distributed Computing Essentially everyone, when they first build a distributed application, makes the following eight assumptions. All prove to be false in the long run and all cause big trouble and painful learning experiences. • The network is reliable • Latency is zero • Bandwidth is infinite • The network is secure • Topology doesn't change • There is one administrator • Transport cost is zero • The network is homogeneous JDP Networking Part I

  33. Network Programming JDP Networking Part I

  34. Introduction to Network Programming Protocols • What is FTP, Telnet, and SMTP? • What is NNTP? • What is HTTP? • Why is Telnet useful (other than for command line interfaces)? Markup Languages • What is SGML? • HTML? • XML? JDP Networking Part I

  35. Topics • Sockets interface • Writing clients and servers • How to use the sockets interface to establish Internet connections between clients and servers • How to copy data from one host to another over an Internet connection. JDP Networking Part I

  36. Sockets Interface Created in the early 80’s as part of the original Berkeley distribution of Unix that contained an early version of the Internet protocols. • Provides a user-level interface to the network. • Underlying basis for all Internet applications. • Based on client/server programming model. The key to network programming is understanding the answers to the following questions: • A socket? • What is a port? • How do we know who to talk to? • What is a well-known port? JDP Networking Part I

  37. Sockets • Sockets as an abstraction provide a conduit through which a process can send data out onto a network to another process. (Both processes could be on the same machine.) • Sockets can be used with both the TCP and the UDP transport layer protocols. • Remember that TCP and UDP sockets need IP addresses and port numbers. • Conceptually this is all that is needed to specify a socket, although the details vary somewhat depending on the programming language and environment used. JDP Networking Part I

  38. Sockets • What is a socket? • To the kernel, a socket is an endpoint of communication. • To an application, a socket is a file descriptor that lets the application read/write from/to the network. • Remember: All I/O devices, including networks, are generally modeled as files. • Clients and servers communicate with each other by reading from, and writing to, socket descriptors. • The main distinction between regular file I/O and socket I/O is how the application “opens” the socket descriptors. JDP Networking Part I

  39. The Java Socket Class Sockets can • Connect to a remote machine • Send data • Receive data • Close a connection • Bind to a port • Listen for incoming connection • Accept connections from remote machines on a bound port JDP Networking Part I

  40. The Java Socket Class The Socket class supports the • Connect to a remote machine [socket = new Socket(…)] • Send data [socket.write()] • Receive data [socket.read()] • Close a connection [socket.close()] What is the kind of data that can be transmitted? • What is a byte stream? Normally a socket is encapsulated in a InputStream class or a Reader class. [More next lecture]. JDP Networking Part I

  41. The Java ServerSocket Class The ServerSocket class additionally supports the • Bind to a port [server_socket.bind()] • Listen for incoming connection [server_socket.listen()] • Accept connections from remote machines on a bound port [server_socket.accept()] JDP Networking Part I

  42. Network Programming • General theory • Create and/or open a socket • Convert a socket to a standard Java I/O class • Input stream • Output stream • Use standard Java I/O for all operations • Works for "normal" TCP connections JDP Networking Part I

  43. Basics • Create a new socket with the Socket() constructor • Provide a host name and port. • Socket attempts to contact remote host • After connection exchange data • Connection is full-duplex • After interactions are done close the connection • Normally a socket is encapsulated in an InputStream class and possibly a Readerclass, and an OutputStreamclass and possibly a Writerclass. [More next lecture]. JDP Networking Part I

  44. Addresses • Connect to a remote machine • Must have fully qualified domain name • Can have short form • How are names known • Local files may have name: /etc/host • System may have an NIS database (Solaris) • Otherwise you must a priori know the name • Must have a port number • How are port numbers found? JDP Networking Part I

  45. Well Known Ports # Network services, Internet style # WELL KNOWN PORT NUMBERS daytime 13/tcp daytime 13/udp qotd 17/tcp quote #Quote of the Day qotd 17/udp quote #Quote of the Day ftp 21/tcp #File Transfer [Control] ssh 22/tcp #Secure Shell Login telnet 23/tcp smtp 25/tcp mail #Simple Mail Transfer http 80/tcp #World Wide Web HTTP nntp 119/tcp usenet #Network News Transfer Protocol https 443/tcp #Secure World Wide Web HTTP syslog 514/udp JDP Networking Part I

  46. Telnet Using telnet to experiment • The telnet program can be used to debug a server • Examples: • telnet condor.depaul.edu 23 • telnet condor.depaul.edu 80 • You can try out being a client process of many protocols that use TCP by using telnet. telnet condor.depaul.edu 80 • But what does a protocol say about the interchange between client and server? • See next slide for an example of a transaction. JDP Networking Part I

  47. Using Telnet to Simulate a HTTP Session $ telnet condor.depaul.edu 80 GET /~dmumaugh/index.html HTTP/1.1 Host: condor.depaul.edu <blank line> HTTP/1.1 200 OK Date: Wed, 02 Apr 2003 20:35:34 GMT Server: Apache/2.0.39 (Unix) PHP/4.2.1 Last-Modified: Wed, 02 Apr 2003 05:06:49 GMT ETag: "29261-103d-e21d0c40" Accept-Ranges: bytes Content-Length: 4157 Content-Type: text/html; charset=ISO-8859-1 <blank line> Blah…Blah…Blah… JDP Networking Part I

  48. Examples JDP Networking Part I

  49. Network I/O • Remember: once a socket is open we have two major operations: • read() • write() • We may also convert a socket into a byte stream using • getInputStream() • getOutputStream() • We can then “wrap” a byte stream into Reader and Writer classes and use more powerful methods: • readLine() – for input streams • println() – for output streams • We will discuss more on network I/O next time JDP Networking Part I

  50. Network I/O Socket s = new Socket( host, port); • Consider the method: String BufferedReader.readLine () • And: BufferedReader reader = new BufferedReader (new InputStreamReader (s.getInputStream(), "UTF-8")); String request = reader.readLine (); • Consider the method: PrintWriter.println (String msg) • And: PrintWriter writer = new PrintWriter (new OutputStreamWriter (s.getOutputStream(), "UTF-8")); writer.println ("GET /index.html HTTP/1.1"); writer.flush (); JDP Networking Part I

More Related