1 / 48

Networked applications

Networked applications. Overview of Networks. Structural view of networks Physical layer: wire, radio, etc. Data link layer: protocol principles, etc Network layer: routing, internetworking Transport layer: protocols (tcp), etc Application layer: email, web, class project

filia
Download Presentation

Networked applications

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. Networked applications

  2. Overview of Networks • Structural view of networks • Physical layer: wire, radio, etc. • Data link layer: protocol principles, etc • Network layer: routing, internetworking • Transport layer: protocols (tcp), etc • Application layer: email, web, class project • We will use one common method at the transport level (TCP/IP via sockets)

  3. Internet Layer • Internetwork: a network of networks • Uses packet switching to send data between machines on this “internet” • Each machine has a unique address on the network (IP address) • Internet Protocol (IP): format of packets used to create these envelops of data • Like mailing a multipage letter by putting each page into a separately mailed envelop • May not arrive in correct order

  4. Internet Protocol (IP) • 1. Hosts (e.g., computers and other devices) are mapped to a set of 32-bit IP addresses. • 128.2.203.179 • 2. The set of IP addresses is mapped to a set of identifiers called Internet domain names. • 128.2.203.179 is mapped to www.cs.cmu.edu • 3. A process on one Internet host can communicate with a process on another Internet host over a connection.

  5. IP address: finding in Windows • Windows 95/98/ME • Click on Start -> Run. Type winipcfg and click OK or press the Enter key. • Windows NT/2000/XP • Click on start, run, type cmd and at the prompt type ipconfig • Type exit to close the command prompt window. • You’ll see something like: Windows 2000 IP Configuration Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : IP Address. . . . . . . . . . . . : 192.168.1.101 Subnet Mask . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . : 192.168.1.1

  6. IP addresses: finding on Mac • Mac OS X • From the Finder, under Applications -> Utilities launch Network Utility. Select the correct ethernet interface. Information and utilities are available from the tabs above. • Or, start a terminal window. • Type ifconfig –a inet This displays network settings for all their network devices First in the above example we have the network settings for the "lo" or "local loopback", next is the actual network settings of your network adapter. • Mac OS versions prior to OS X. • Open Control Panel and click to open TCP/IP. Select the correct ethernet interface in the "Connect via:" pull down menu.

  7. IP address: finding in linux • For Linux or Unix users, to view their IP address or network information, users must have administrator or root privileges. • Open the Linux or Unix shell if you are utilizing a GUI interface for your Linux or Unix machine. • From the prompt, type ifconfig eth0and press enter. You’ll see: eth0 Link encap:Ethernet HWaddr 00:A0:24:72:EB:0A inet addr:10.10.10.2 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5569799 errors:32 dropped:32 overruns:0 frame:6 TX packets:3548292 errors:0 dropped:0 overruns:0 carrier:3 Collisions:14 Interrupt:18 Base address:0xda00

  8. IP addresses: finding a remote address • The whois utility looks up records in the databases maintained by several Network Information Centers (NICs). whois [-h hostname] domainName The square brackets are not written, they indicate an option Example: whois ithaca.edu Or, if you know of a whois server like whois.educause.net (stores edu names): whois -h whois.educause.net ithaca.edu

  9. IP addresses: finding a remote address Barr$whois ithaca.edu Domain Name: ITHACA.EDU Registrant: Ithaca College Information Technology Services Job Hall Ithaca, NY 14850-7028 UNITED STATES Administrative Contact: Mike Testa Director, Infrastructure & Communication Services Ithaca College Information Technology Services 305 Job Hall Ithaca, NY 14850-7028 UNITED STATES (607) 274-5756 mtesta@ithaca.edu Technical Contact: Bill Weeks Network Services Manager Ithaca College Name Servers: NS1.ITHACA.EDU 209.51.64.22 NS2.ITHACA.EDU 66.152.113.102 RESOLVER3.ITHACA.EDU 208.81.240.2 Domain record activated: 18-Jun-1990 Domain record last updated: 28-Jun-2010 Domain expires: 31-Jul-2013

  10. Transport Layer • Transmission Control Protocol (TCP): • Used to create reliable byte-streaming communication • Ensures that messages are passed error-free from one machine to another on an internet • Divides data into discrete messages before passing them on to the IP layer • At the receiving end, protocol used to “reconstruct” the packets correctly

  11. Application layer • Applications utilize TCP/IP communication by having the sender and the receiver create end points called Sockets

  12. 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.

  13. 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. • In Unix all I/O devices, including networks, are modeled as files. • Clients and servers communicate with each other by reading from and writing to socket descriptors.

  14. Application layer • Each socket has a socket number (address) • IP address of the host computer • Port number local to that host to which the socket is attached • Port numbers below 1024 are reserved (e.g. for email and FTP) • Some addresses are “well known”, • Port 7: Echo server • Port 23: Telnet server • Port 25: Mail server • Port 80: Web server • You must choose a port not already in use

  15. Application Layer • To use TCP service a connection must be explicitly established between a socket on the sending machine and a socket on the receiving machine • A socket may be used for multiple connections at the same time. • A computer (and/or application) may have multiple open socket connections

  16. process process TCP with buffers, variables TCP with buffers, variables socket socket Socket-programming using TCP TCP service: reliable transfer of bytesfrom one process to another controlled by application developer controlled by application developer controlled by operating system controlled by operating system internet host or server host or server 2: Application Layer

  17. Sockets Computer IP: 147.129.30.2 OS application Port 80 socket Physical connection (e.g. ethernet, RS232) Port 5678

  18. rio_writen rio_readlineb Client / Server Session rio_readlineb rio_writen EOF rio_readlineb close close Overview of the Sockets Interface Client Server socket socket bind open_listenfd open_clientfd listen Connection request connect accept Await connection request from next client

  19. Discovering used ports on a machine use netstat.exe program (shipped with windows). • Start "DOS Command Prompt" using run-> cmd • type netstat –an and then press Enter, • use command "more" to stop when your listing contains to much lines (netstat -na | more). Each line of netstat's listing contains these information: * Protocol type - it can be TCP or UDP. Two sockets can use the same port number when they use different protocols. * Local Address - local IP address which is used. In most cases it is 0.0.0.0 (any = not bound to the specific IP address. It can accept connection from any PC's interface). When IP address is specified then only connection from interface with the same IP address are accepted. The port number immediately follows the IP address Local Address field contains port number which is used to accept connection or receive UDP data. * Foreign Address - address of PC on remote side. It will be displayed when connection is established. * State - state of socket. You can see this states: LISTENING - socket waits for connection (or data in case of UDP socket) ESTABLISHED - connection to the remote side is established CLOSE_WAIT, TIME_WAIT - socket waits for connection close or other type of negotiation. To determine whether desired port number is already in use you must check Local Address field on all lines.

  20. Discovering used ports on a machine Example: TCP 0.0.0.0:25 0.0.0.0:0 LISTENING Some application which uses port 25 (SMTP server port) is running. To use P+'s mail server you must at first stop this application. Notice: When finding used (or free) port number stop Proxy+ first.

  21. Discovering used ports on a machine On Linux: • Read the /etc/services file. • If you want the list of open ports, try netstat -nlp • Arguments: n = show network addresses as numbers, l = show listening sockets, p = show pid and name of program

  22. Discovering used ports on a machine On Macs: • Read the /etc/services file. • If you want the list of open ports, try netstat –n | more • The port follows the IP address

  23. Client-Server Model • Networked applications may be structured any number of ways • One popular structure is client-server • Server • Usually unique • Provides a service • Runs continuously • Clients • Usually many • Send request for service, receive result from server • Connect and disconnect as needed

  24. Client-Server processing 1. Client sends request Client process Server process Resource 4. Client handles response 2. Server handles request 3. Server sends response

  25. 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)

  26. Servers • Servers are long-running processes (daemons in Unix). • Created at boot-time (typically) by the init process (process 1) • Run continuously until the machine is turned off. • A machine that runs a server process is also often referred to as a “server.”

  27. Servers • 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 • See http://www.answersthatwork.com/Download_Area/ATW_Library/Networking/Network__2-List_of_Common_TCPIP_port_numbers.pdf

  28. 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 On Mac/Linux type: more/etc/services for a comprehensive list of well known ports

  29. Example: web service • Your web browser is the client • Computer containing the pages you are trying to access runs the web server • Your computer requests the page • Server sends the page • Many other people may be requesting the same page • Note: these are distinct applications. Your browser (client) never acts as a server

  30. Structuring networked applications • As you develop networked applications: • Is the client-server model a good model? • Minimizes network communication? • Minimizes computational redundancy? • If so: • Which classes will be on the server side (e.g. provide a service)? • Which must be on the client side?

  31. TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server application viewpoint Client-Server programming with TCP Client must contact server • server process must first be running • server must have created socket (door) that welcomes client’s contact Client contacts server by: • creating client-local TCP socket • specifying IP address, port number of server process • When client creates socket: client TCP establishes connection to server TCP • When contacted by client, server TCP creates new socket for server process to communicate with client • allows server to talk with multiple clients • source port numbers used to distinguish clients 2: Application Layer

  32. create socket, connect to hostid, port=x create socket, port=x, for incoming request: clientSocket = Socket() welcomeSocket = ServerSocket() TCP connection setup wait for incoming connection request connectionSocket = welcomeSocket.accept() send request using clientSocket read request from connectionSocket write reply to connectionSocket read reply from clientSocket close connectionSocket close clientSocket Client/server socket interaction: TCP Server (running on hostid) Client 2: Application Layer

  33. Stream jargon • A stream is a sequence of characters that flow into or out of a process. • An input stream is attached to some input source for the process, e.g., keyboard or socket. • An output stream is attached to an output source, e.g., monitor or socket. Client process client TCP socket 2: Application Layer

  34. Networked applications in JAVA • JAVA provides built-in support for TCP/IP network communication (java.net package) • Within the server application, create a server socket: ServerSocket myServer = new ServerSocket(port); • Attempting to use a port already in use results in a BindException being thrown • Use try/catch to handle exceptions

  35. Networked applications in JAVA • Once the server socket is created, listen for connections: Socket clientConnection = myServer.accept(); • This command will block until a connection is established

  36. Networked applications in JAVA • Within a Client application, create a socket and connect to a specific server: Socket serverConnection = new Socket(server, port); • server is a string containing the host name or IP address • The host is the computer running the server application

  37. Examples Socket connectToServer = new Socket(“computer1.ithaca.edu”, 8000); Socket anotherConnection = new Socket(“149.164.29.27”, 8000); • You can only use first if you are running DNS or have a hosts table • “localhost” may be used if client/server on same machine

  38. Networked applications in JAVA • Once the server accepts the connection, communication is conducted as for any other JAVA I/O stream: InputStream isFromServer = serverConnection.getInputStream(); OutputStream osToServer = serverConnection.getOutputStream();

  39. Networked applications in JAVA • Since JAVA I/O streams read/write bytes, wrap your I/O streams with classes that read data values (int, double, String) • BufferedReader will read data • PrintWriter will write data

  40. Socket programming with TCP Example client-server app: 1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (inFromServer stream) 2: Application Layer

  41. Example: Java client (TCP) import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws IOException { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); This works, but don’t do it! Catch and handle all exceptions. Create input stream Create client socket, connect to server Create output stream attached to socket 2: Application Layer

  42. Example: Java client (TCP), cont. Create input stream attached to socket BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } } Note that you must send a newline char o.w. the server will wait forever! Send line to server Read line from server 2: Application Layer

  43. Example: Java server (TCP) import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws IOException { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); This works, but don’t do it! Catch and handle all exceptions Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket 2: Application Layer

  44. Example: Java server (TCP), cont DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } } } Create output stream, attached to socket Read in line from socket Write out line to socket End of while loop, loop back and wait for another client connection 2: Application Layer

  45. TCP observations & questions • Server has two types of sockets: • ServerSocket and Socket • When client knocks on serverSocket’s “door,” server creates connectionSocket and completes TCP conx. • Dest IP and port are not explicitly attached to segment. • Can multiple clients use the server? 2: Application Layer

  46. Example • An example: • Server calculates area given radius • Client gets radius from user, requests area calculation

  47. server radius Area client client radius

  48. Example • Client.doc • Server.doc

More Related