FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 28,… (Client-Server Concept, Use of Protocol Ports, Socket API)

Slides:



Advertisements
Similar presentations
28.2 Functionality Application Software Provides Applications supply the high-level services that user access, and determine how users perceive the capabilities.
Advertisements

Data Communications and Networking (Third Edition)
CS335 Networking & Network Administration Tuesday, May 25, 2010.
Socket Programming.
© 2007 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets with Internet Applications, 4e By Douglas.
Chapter 25 Internet Routing Internetworking Technology How routing tables are built initially How routing software updates the tables as needed. Propagation.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
© 2007 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets with Internet Applications, 4e By Douglas.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
© 2007 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets with Internet Applications, 4e By Douglas.
1 Computer Networks and Internets, 5e By Douglas E. Comer Lecture PowerPoints Adapted from the notes By Lami Kaya, © 2009 Pearson Education.
What Is TCP/IP? The large collection of networking protocols and services called TCP/IP denotes far more than the combination of the two key protocols.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
1 Transport Layer Computer Networks. 2 Where are we?
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
Chapter 24 - Socket Interface Introduction API The Socket API Sockets and socket libraries Sockets and UNIX I/O The socket API Summary of socket system.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 31,32,34 (DNS, , TELNET, FTP)
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 2.5 Internetworking Chapter 25 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
 Wind River Systems, Inc Chapter - 13 Network Programming.
FALL 2003CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 28,… (Client-Server Concept, Use of Protocol Ports, Socket API, DNS, ,
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
CSC 600 Internetworking with TCP/IP Unit 2: Client-Server Model and Sockets(Ch.2, 3, 21, 22) Dr. Cheer-Sun Yang Fall 2000.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Client-Server Model of Interaction Chapter 20. We have looked at the details of TCP/IP Protocols Protocols Router architecture Router architecture Now.
Introduction to Socket
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Socket Programming Introduction. Socket Definition A network socket is one endpoint in a two-way communication flow between two programs running over.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Part 4: Network Applications Client-server interaction, example applications.
The Client Server Model And Software Design
Berkeley Socket Abstraction
UNIX Sockets Outline UNIX sockets CS 640.
© 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets, 5e By Douglas E. Comer Lecture PowerPoints.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Client-server communication Prof. Wenwen Li School of Geographical Sciences and Urban Planning 5644 Coor Hall
1 K. Salah Application Layer Module K. Salah Network layer duties.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Process-to-Process Delivery:
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
1 Chapter 24 Internetworking Part 4 (Transport Protocols, UDP and TCP, Protocol Port Numbers)
Sockets and Beginning Network Programming
Chapter 3 Internet Applications and Network Programming
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
CSI 4118 – UNIVERSITY OF OTTAWA
Client/Server Example
Client-Server Interaction
Interacting With Protocol Software
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
CSI 4118 – UNIVERSITY OF OTTAWA
Exceptions and networking
Presentation transcript:

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 28,… (Client-Server Concept, Use of Protocol Ports, Socket API)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA2 Functionality Transport layer and layers below Basic communication Reliability Application layer Abstractions Files Services Databases Names

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA3 Dichotomy of Duties Network Transfers bits Operates at application’s request Applications determine What to send When to send Where to send Meaning of bits

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA4 Important Point Although an internet system provides a basic communication service, the protocol software cannot initiate contact with, or accept contact from, a remote computer. Instead, two application programs must participate in any communication: one application initiates communication and the other accepts it.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA5 How Two Application Programs Make Contact One application Begins execution first Waits passively at prearranged location Another application Begins execution later Actively contacts first program Called client-server interaction

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA6 Client-Server Paradigm Used by all network applications Passive program called a server Active program called a client

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA7 Internet Communication All network applications use a form of communication known as the client- server paradigm. A server application waits passively for contact, while a client application initiates communication actively.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA8 Characteristics of a Client Arbitrary application program Becomes client temporarily Can also perform other computations Invoked directly by user Runs locally on user’s computer Actively initiates contact with a server Contacts one server at a time

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA9 Characteristics of a Server Special-purpose, privileged program Dedicated to providing one service Can handle multiple remote clients simultaneously Invoked automatically when system boots Executes forever Needs powerful computer and operating system Waits passively for client contact Accepts requests from arbitrary clients

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA10 Terminology Server An executing program that accepts contact over the network Server-class computer Hardware sufficient to execute a server Informally Term server often applied to computer

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA11 Direction of Data Flow Data can flow From client to server only From server to client only In both directions Application protocol determines flow Typical scenario Client sends request(s) Sever sends response(s)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA12 Key Idea Although the client initiates contact, information can flow in either or both directions between a client and server. Many services arrange for the client to send one or more requests and the server to return one response for each request.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA13 Clients, Servers, and Other Protocols Clients and servers are application programs

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA14 Server CPU Use Facts Server operates like other applications Uses CPU to execute instructions Performs I/O operations Waiting for data to arrive over a network does not require CPU time Consequence Server program only uses CPU when servicing a request

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA15 Multiple Services Can have multiple servers on single computer Servers only use processor when handling a request Powerful hardware required to handle many services simultaneously

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA16 Illustration of Multiple Servers Each server offers one service One server can handle multiple clients

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA17 Identifying a Service Protocol port number used Each service given unique port number, P Server Informs OS it is using port P Waits for requests to arrive Client Forms request Send request to port P on server computer

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA18 The Point About Ports Transport protocols assign each service a unique port identifier. A server must specify the identifier when it begins execution. A client must specify the identifier when it requests transport protocol software to contact a server. Protocol software on the server computer uses the identifier to direct an incoming request to the correct server.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA19 In Theory Port numbers are merely integers Any server could use any port number

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA20 In Practice Protocol port numbers used as service identifiers Need uniform numbering To allow arbitrary client to contact server on arbitrary machine To avoid inventing “directory assistance” mechanism Port numbers Uniform throughout Internet Set by standards bodies

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA21 Terminology Sequential program Typical of most programs Single thread of control Concurrent program Multiple threads of control Execution proceeds “in parallel” More difficult to create

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA22 Servers and Concurrency Sequential server Also called iterative Handles one request at a time Concurrent server Can handle multiple requests at a time No waiting

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA23 Delay in Servers Concurrent server Server creates new thread of control to handle each request Client only waits for its request to be processed Sequential server Client waits for all previous requests to be processed as well as for its request to be processed Unacceptable to user if long request blocks short requests

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA24 Concurrency in Servers Concurrent execution is fundamental to servers because concurrency permits multiple clients to obtain a given service without having to wait for the server to finish previous requests. In a concurrent server, the main server thread creates a new service thread to handle each client.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA25 Protocol Ports and Concurrent Servers Apparent problem One port number assigned to each service Concurrent server has multiple copies (threads) running Client and server may interact Messages sent to server’s port must be delivered to correct copy

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA26 Protocol Ports and Concurrent Servers (continued) Solution to problem: use information about client as well as server to deliver incoming packets TCP uses four items to identify connection Server’s IP address Server’s protocol port number Client’s IP address Client’s protocol port number

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA27 Demultiplexing in a Concurrent Server Transport protocols assign an identifier to each client as well as to each service. Protocol software on the server’s machine uses the combination of client and server identifiers to choose the correct copy of a concurrent server.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA28 Variations on a Theme A server can use Connectionless transport (UDP) Connection-oriented transport (TCP) Both for a single service A single server can offer multiple services Often used for “trivial” services Server uses multiple port numbers simultaneously

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA29 Variations on a Theme (cont) A server can Maintain interaction with a client for days or hours Send a short response and terminate interaction Perform I/O on the local computer Become a client for another service (potential cycle problem)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA30 Example of Circularity Time server Returns time of day File server Allows client to read or write a file Calls time server when generating time stamp for file Suppose programmer modifies time server to log requests to a file

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA31 Interacting with Protocol Software Client or server uses transport protocols Protocol software inside OS Applications outside OS Mechanism needed to bridge the two Called Application Program Interface (API)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA32 Application Program Interface Part of operating system Permits application to use protocols Defines Operations allowed Arguments for each operation

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA33 Socket API Originally designed For BSD UNIX To use with TCP/IP protocols Now Industry standard Available on many operating systems

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA34 Sockets and Socket Libraries A socket library can provide applications with a socket API on a computer system that does not provide native sockets. When an application calls one of the socket procedures, control passes to a library routine that makes one or more calls to the underlying operating system to implement the socket function.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA35 Socket OS abstraction (not hardware) Created dynamically Persists only while application runs Referenced by a descriptor

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA36 Descriptor Small integer One per active socket Used in all operations on socket Generated by OS when socket created Only meaningful to application that owns socket In UNIX, integrated with file descriptors

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA37 Creating a Socket Application calls socket function OS returns descriptor for socket Descriptor valid until application closes socket or exits Common: protofamily = PF_INET, type = SOCK_STREAM or SOCK_DGRAM desc = socket(protofamily,type,proto);

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA38 Socket Functionality Socket completely general Can be used By client By server With a CO transport protocol With a CL transport protocol To send data, receive data, or both Large set of operations

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA39 Socket Operations Close Terminate use of socket Permanent close(socket);

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA40 Socket Operations Bind Specify protocol port for a socket Specify local IP address for a socket Can use INADDR_ANY for any IP address bind(socket,localaddr,addrlen);

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA41 Generic Address Format struct sockaddr { u_char sa_len; /*length of address*/ u_char sa_family; /*family of address*/ char sa_data[14]; /*address itself*/ }

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA42 TCP/IP Address Format struct sockaddr_in { u_char sin_len; /*length of address*/ u_char sin_family; /*family of address*/ u_short sin_port; /*protocol port number*/ struct in_addr sin_addr; /*IP address*/ char sin_zero[8]; /*not used(set to zero)*/ }

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA43 Socket Operations (continued) Listen Used by server Prepares socket to accept incoming connections Accept Used by server Waits for next connection and returns new socket listen(socket,queuesize); newsock = accept(socket,caddr,caddrlen);

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA44 Socket Operations (continued) Connect Used by client Either Performs a TCP connection Fully specifies addresses for UDP connect(socket,saddr,saddrlen);

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA45 Two Purposes of the Connect Function The connect function, which is called by clients, has two uses. With connection- oriented transport, connect establishes a transport connection to a specified server. With connectionless transport, connect records the server’s address in the socket, allowing the client to send many messages to the same server without specifying the destination address with each message.

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA46 Socket Operations (continued) Send, sendto, and sndmsg Transfer outgoing data from application send(socket,data,length,flags); sendmsg(socket,msgstruct,flags); sendto(socket,data,length,flags, destaddr,addrlen);

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA47 Format of msgstruct struct msgstruct { struct sockaddr *m_saddr; /*dest address*/ struct datavec *m_dvec; /*message (vector)*/ int mdvlength; /*size of vector*/ struct access *m_rights; /*access rights*/ int m_alength; /*size of access rights*/ }

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA48 Socket Operations (continued) Recv, recvfrom, and recvmsg Transfer incoming data to application recv(socket,buffer,length,flags); recvmsg(socket,msgstruct,flags); recvfrom(socket,buffer,length,flags, senderaddr,saddrlen);

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA49 Socket Operations (continued) Many additional functions Supply support and utility services Some implemented as library calls

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA50 Examples of Socket Support Functions Gethostbyname Maps domain name to IP address Example of argument Getprotobyname Maps name of protocol to internal number Argument usually “tcp” or “udp”

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA51 Example Service Purpose Count times involved Return printable ASCII message Connection-oriented protocol Sequential execution (not concurrent)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA52 Example Client Open TCP connection to server Iterate until end-of-file Receive text Print characters received Close connection Exit

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA53 Example Server Create socket and put in passive mode Iterate forever Accept next connection, get new socket Increment count and send text message Close socket for connection Notes Main socket remains open Server never exits

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA54 Socket Calls in Client and Server Client closes socket after use Server never closes original socket

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA55 Code for Client Arguments to program Host Protocol port Both optional Many details Minor incompatibilities among socket implementations Unix Microsoft Use C language #ifdef

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA56 Example Client Code (1)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA57 Example Client Code (2)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA58 Example Client Code (3)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA59 Example Client Code (4)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA60 Example Client Code (5)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA61 Code For Server Arguments to program Protocol port C language # ifdef s for socket variants

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA62 Example Server Code (1)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA63 Example Server Code (2)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA64 Example Server Code (3)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA65 Example Server Code (4)

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA66 Stream Interface Sender Calls send Specifies number of octets in call TCP Divides stream into segments Receiver Calls recv repeatedly Receives one or more octets per call Count of zero means “end of file” Size received unrelated to size sent

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA67 Summary Applications use client-server paradigm for interaction Client Arbitrary application Actively initiates communication Must know server’s IP address Protocol port number

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA68 Summary (continued) Server Specialized program Runs forever Usually offers one service Passively waits for clients Can handle multiple clients simultaneously

FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA69 Summary (continued) Socket API Standardized Specifies interface between applications and protocol software Socket Operating system abstraction Created dynamically Used by clients and servers