Chapter 5 Socket API - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Chapter 5 Socket API

Description:

Socket API adds a new abstraction for network communication, the socket. ... Application only use open to crate file descriptor ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 10
Provided by: PROFE172
Category:

less

Transcript and Presenter's Notes

Title: Chapter 5 Socket API


1
Chapter 5 Socket API
  • 1980, a group at UC Berkeley create a interface
    that applications use to communicate.
  • Known as socket API or socket interface
  • System is known as Berkeley UNIX or BSD UNIC

2
Specifying a protocol interface
  • Two broad approaches
  • Define functions specifically to support TCP/IP
    communication
  • Define functions that support network
    communication in general, and use parameters to
    make TCP/IP communication a special case.
  • Because the designer at Berkeley wanted to
    accommodate multiple sets of communication
    protocol, they used the second approach.

3
  • In fact, they provides for generality far beyond
    TCP/IP. They allowed for multiple families of
    protocols, with all TCP/IP protocols represented
    as single family(family PF_INET)
  • The socket API provides generalized functions
    that support network communication using many
    possible protocols as a single protocol family.
    The calls allow the programmer to specify the
    type of service required rather than the name of
    specific protocol.

4
Socket abstraction
  • File descriptors
  • Open function create a file descriptor
  • The OS maintains a separate file descriptor as an
    array of pointers to internal data structure
  • Application program only need to remember the
    descriptor and use it

5
  • Socket API adds a new abstraction for network
    communication, the socket.
  • Each active socket is identified by a small
    integer called its socket descriptor
  • OS provides a separate system function, socket,
    that applications call to create a socket
  • Application only use open to crate file
    descriptor
  • Once the socket has been created, an application
    must make additional system calls to specify the
    details of its exact use.

6
System data structure for sockets
Operating system
Descriptor table ( one per process)
Family PF_INET
0
ServiceSOCK_STREAM
1
Local IP
2
Remote IP
3
Local Port
4
Remote Port
7
Using sockets
  • A socket used by a server to wait for an incoming
    connection is called a passive socket
  • A socket used by a client to initiate a
    connection is called an active socket.
  • The sockets are created the same way initially

8
Endpoint address
  • When a socket is created, it does not contain
    detailed information about how it will be used.
    (port number, IP address)
  • ICP/IP protocols define a communication endpoint
    to consist of an IP address and a protocol port
    number.
  • It allows each protocol family to specify
    endpoints however it likes
  • TCP/IP protocols all use a single address
    representation, with address family AF_INET

9
Generic address structure
  • Struct sockaddr
  • u_char sa_len // total length
  • U_short sa_family // type of address
  • char sa_data14 // value of address
Write a Comment
User Comments (0)
About PowerShow.com