The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.

Slides:



Advertisements
Similar presentations
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Advertisements

Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Socket Programming 0.
Data Communications and Networking (Third Edition)
Slide 1 Client / Server Paradigm. Slide 2 Outline: Client / Server Paradigm Client / Server Model of Interaction Server Design Issues C/ S Points of Interaction.
CS335 Networking & Network Administration Tuesday, May 25, 2010.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Socket Programming.
1 Generic Transport Service Primitives Listen –notify Transport layer a call is expected Connect –establish Transport layer connection Send (or Write)
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
© 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.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Networks 1 CS502 Spring 2006 Network Input & Output CS-502 Operating Systems Spring 2006.
CS-3013 & CS-502, Summer 2006 Network Input & Output1 CS-3013 & CS-502, Summer 2006.
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.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
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.
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.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
User Datagram Protocol (UDP) Chapter 11. Know TCP/IP transfers datagrams around Forwarded based on destination’s IP address Forwarded based on destination’s.
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Position of application layer. Application layer duties.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 3.1 Internet Applications Ch. 28,… (Client-Server Concept, Use of Protocol Ports, Socket API)
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 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
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.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Berkeley Socket Abstraction
UNIX Sockets Outline UNIX sockets CS 640.
Inter-Process Communication 9.1 Unix Sockets You may regard a socket as being a communication endpoint. –For two processes to communicate, both must create.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
1 Kyung Hee University Chapter 11 User Datagram Protocol.
UDP: User Datagram Protocol Chapter 12. Introduction Multiple application programs can execute simultaneously on a given computer and can send and receive.
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.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Socket Abstraction and Interprocess Communication
Sockets and Beginning Network Programming
Chapter 3 Internet Applications and Network Programming
MCA – 405 Elective –I (A) Java Programming & Technology
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Interacting With Protocol Software
UNIX Sockets Outline Homework #1 posted by end of day
Socket Abstraction and Interprocess Communication
Starting TCP Connection – A High Level View
Socket Abstraction and Interprocess Communication
CSC Advanced Unix Programming, Fall 2015
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Presentation transcript:

The Socket Interface Chapter 21

Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between application programs and TCP/IP protocols Will look at one example that is a de facto standard Will look at one example that is a de facto standard Things to keep in mind Things to keep in mind Application/protocol interaction not in the standards Distinguish between interface and protocols Distinguish between interface and protocols In practice, details of interface depend on OS Example is from BSD UNIX operating system Is a widely accepted, de facto standard Is a widely accepted, de facto standard Operations listed are NOT part of the TCP/IP standards Operations listed are NOT part of the TCP/IP standards

UNIX I/O Paradigm Unix is a process oriented OS Applications execute as a user level process Applications execute as a user level process Application interacts with OS via system calls Application interacts with OS via system calls Act just like procedure calls I/O is open-read-write-close Call open to get file descriptor for file or device Call open to get file descriptor for file or device Call read or write to do I/O Call read or write to do I/O Call close to indicate done with object Call close to indicate done with object

Adding Network I/O to UNIX Originally, all I/O was open-read-write-close Needed to add network protocols to UNIX Interactions more complex Interactions more complex Passive server code as well as active client code Specify datagram address when send vs when open Abandoned the above paradigm Abandoned the above paradigm Additions made I/O interface more complex Additions made I/O interface more complex Needed general mechanism for any protocol interface

Socket Abstraction Socket is basis for network I/O Mechanism that provides an endpoint for communication Mechanism that provides an endpoint for communication Create when needed; get integer to reference Create when needed; get integer to reference Application can choose address binding method Application can choose address binding method TCP connection Both endpoints must be specified Both endpoints must be specified Use for UDP Remote endpoint can be left unspecified Remote endpoint can be left unspecified Pass as argument each time message is sent Pass as argument each time message is sent

Creating a Socket Use socket function to create a socket result = socket(pf, type, protocol) result = socket(pf, type, protocol) pf specifies protocol family pf specifies protocol family type specifies communication type type specifies communication type Reliable stream; connectionless datagram; raw protocol specifies a specific protocol in the family protocol specifies a specific protocol in the family Need more than just family and type Ex: pipe in UNIX family cannot do packet delivery Programmer must know protocol family well

Socket Inheritance & Termination Two system calls used to start new application programs fork fork Creates separate copy of currently executing process New copy inherits all open file descriptors & sockets exec exec Desired application program loaded into the process Still retains access to inherited sockets (and FDs)

Both old and new processes share the existing sockets OS keeps a count associated with each socket OS keeps a count associated with each socket Knows how many applications are using it Programmer must ensure it is done in a meaningful way Programmer must ensure it is done in a meaningful way To close a socket: close(socket) Or, open sockets closed upon process termination Or, open sockets closed upon process termination close actually decrements count; destroy socket when it reaches zero close actually decrements count; destroy socket when it reaches zero

Specifying a Local Address Upon creation, sockets have no association to local or destination addresses TCP/IP TCP/IP No local protocol port number has been assigned No destination port or IP address has been specified Client may not care what local address is Client may not care what local address is Server process at well-know port will care Uses bind function to establish specific local addrs

Connecting Sockets to Destination Addresses Initially, sockets are unconnected Not associated with any remote destination Not associated with any remote destination Function connect binds a permanent destination Function connect binds a permanent destination Form: Form: connect(socket, destaddr, addrlen) Semantics depend upon underlying protocol Semantics depend upon underlying protocol Reliable stream service: build TCP connection Connectionless service: stores dest address locally

Sending Data Through a Socket Sockets are used to transmit data Five possible functions Five possible functionswrite write(socket, buffer, length) write(socket, buffer, length) buffer contains the address of the data to be sent buffer contains the address of the data to be sent Works with connected sockets only Works with connected sockets onlywritev writev(socket, iovector, vectorlen) writev(socket, iovector, vectorlen) iovector contains a sequence of pointers to blocks of bytes iovector contains a sequence of pointers to blocks of bytes Works with connected sockets only Works with connected sockets only

send send(socket, message, length, flags) send(socket, message, length, flags) message gives the address of the data message gives the address of the data flags controls the transmission flags controls the transmission Works with connected sockets only Works with connected sockets onlysendto sendto(socket, message, length, flags, destaddr, addrlen) sendto(socket, message, length, flags, destaddr, addrlen) destaddr specifies the socket address structure destaddr specifies the socket address structuresendmsg sendmsg(socket, messagestruct, flags) sendmsg(socket, messagestruct, flags) messagestruct is a structure with the required information messagestruct is a structure with the required information Used when sendto makes the program inefficient or hard to read Used when sendto makes the program inefficient or hard to read

Receiving Data Through a Socket Analogous five input functions read(descriptor, buffer, length) read(descriptor, buffer, length) readv(descriptor, iovector, vectorlen) readv(descriptor, iovector, vectorlen) recv(socket, buffer, length, flags) recv(socket, buffer, length, flags) recfrom(socket, buffer, length, flags, fromaddr, addrlen) recfrom(socket, buffer, length, flags, fromaddr, addrlen) recmsg(socket, messagestruct, flags) recmsg(socket, messagestruct, flags)

Text gives examples of many socket functions and library routines Can read over at your convenience Can read over at your convenience

How a Server Accepts Connections Once a socket is established, the server waits for a connection Uses function accept to do so Uses function accept to do so newsock = accept(socket, addr, addrlen) When a request arrives: addr and addrlen filled in addr and addrlen filled in New socket created that has destination connected to client New socket created that has destination connected to client Original socket still remains open Original socket still remains open Call to accept returns Call to accept returns

Server can handle connections one of two ways Server can handle connections one of two waysIteratively Server handles request, closes new socket, calls accept Server handles request, closes new socket, calls acceptConcurrently Master creates slave to handle request at new socket Master creates slave to handle request at new socket Closes its copy of the new socket Calls accept Slave closes socket when it finishes, and then terminates Slave closes socket when it finishes, and then terminates Multiple processes will be using same local protocol port Multiple processes will be using same local protocol port Ok because pair of endpoints defines a connection Master server has wildcard in foreign destination All other processes have a specific foreign dest

Socket Library Calls Socket API also offers set of library routines Perform useful functions related to networking Perform useful functions related to networking System calls pass control to computer’s OS Library routines are like other program procedures Figure 21.5

Many socket library routines provide database services Many socket library routines provide database services Determine names of machines & network services Determine protocol port numbers Find out other related information Sections examine groups of library routines Sections examine groups of library routines

Example Client & Server Text gives example C program using the socket API to access TCP/IP protocols Implements simple whois client & server Implements simple whois client & server Client is an application that a user invokes Client is an application that a user invokes Two arguments: name of remote machine and user Creates socket, uses TCP, binds socket to whois port Server only slightly more complex Server only slightly more complex Listens on well-know whois port Returns requested info from UNIX password file

Summary API for TCP/IP depends on details of OS Because TCP/IP protocol SW resides inside OS Because TCP/IP protocol SW resides inside OS Interface not specified by protocol standard Interface not specified by protocol standard Examined socket API Originally designed for BSD UNIX Originally designed for BSD UNIX Widely used by many vendors (like Microsoft) Widely used by many vendors (like Microsoft) Uses UNIX open-read-write-close paradigm Uses UNIX open-read-write-close paradigm

To use TCP, application program must: To use TCP, application program must: Create socket Bind addresses to it Accept incoming connections Communicate using read or write primitives Close when finished Many library routines available, also Many library routines available, also Socket interface is popular and widely supported Socket interface is popular and widely supported If not have socket facilities in OS, often provide socket library Underlying OS will use different set of system calls Underlying OS will use different set of system calls