Chapter 2: Socket Programming Chapter goal: a Program interface to rotocol Socket API Socket programming model 哈工大计算机学院李全龙 Network Application Development Socket Programming
哈工大计算机学院 李全龙 Network Application Development Socket Programming 1 Chapter 2: Socket Programming Chapter goal: Program interface to protocol Socket API Socket programming model
Chapter 2: Socket Programming Chapter goal: Program interface to protocol Socket API Socket programming model 哈工大计算机学院李全龙 Network Application Development Socket Programming 2
哈工大计算机学院 李全龙 Network Application Development Socket Programming 2 Chapter 2: Socket Programming Chapter goal: Program interface to protocol Socket API Socket programming model
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) 哈工大计算机学院李全龙 Network Application Development Socket Programming 3
哈工大计算机学院 李全龙 Network Application Development Socket Programming 3 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)
mosely specified protocol software interface TCP/IP protocol software is part of the computer' s system software TCP/IP was designed to operate in a multi-vendor environment TCP/IP does not define details of aPf The interface between TCP/IP and applications that use it has been loosely specified TCP/IP standards do not specify the details of how application software interfaces with TCP/IP protocol software hey only suggest the required functionality, and allow system designers to choose the details when creating an API 哈工大计算机学院李全龙 Network Application Development Socket Programming 4
哈工大计算机学院 李全龙 Network Application Development Socket Programming 4 Loosely specified protocol software interface TCP/IP protocol software is part of the computer’s system software. TCP/IP was designed to operate in a multi-vendor environment. TCP/IP does not define details of API The interface between TCP/IP and applications that use it has been loosely specified. TCP/IP standards do not specify the details of how application software interfaces with TCP/IP protocol software They only suggest the required functionality, and allow system designers to choose the details when creating an API
Advantages and disadvantages of Loose specification Advantages: Flexibility and tolerance Different os select own implementation Disadvantages: Designers can make the interface details different for each OS Less portable across machines In practice, only a few aPIs have been developed for use with TCP /IP Berkeley UNIX: socket interface, or sockets nAT&T, System V UNIX:工 Windows: windows sockets interface, WINSOCK 哈工大计算机学院李全龙 Network Application Development Socket Programming 5
哈工大计算机学院 李全龙 Network Application Development Socket Programming 5 Advantages and disadvantages of Loose specification Advantages: Flexibility and tolerance. Different OS select own implementation. Disadvantages: Designers can make the interface details different for each OS. Less portable across machines. In practice, only a few APIs have been developed for use with TCP/IP. Berkeley UNIX: socket interface, or sockets AT&T, System V UNIX: TLI Windows: windows sockets interface, WINSOCK
API functionality API must support Allocate local resources for communication Specify local and remote communication endpoints Initiate a connection( client side) Wait for a connection (server side) Send or receive data Determine when data arrives Generate urgent data Terminate a connection gracefully Handle connection termination from the remote site abort communication Handle error condition or a connection abort Release local resources when communication finishes 哈工大计算机学院李全龙 Network Application Development Socket Programming 6
哈工大计算机学院 李全龙 Network Application Development Socket Programming 6 API functionality API must support: Allocate local resources for communication Specify local and remote communication endpoints Initiate a connection (client side) Wait for a connection (server side) Send or receive data Determine when data arrives Generate urgent data Terminate a connection gracefully Handle connection termination from the remote site Abort communication Handle error condition or a connection abort Release local resources when communication finishes
Conceptual interface specification The TCP/IP standards do not leave implementors without any guidance They specify a conceptual interface: a set of procedures and functions The conceptual interface defined by tcp/Ip standards does not specify data representations or programming details It merely provides an example of one possible interface that an OS can offer to application programs that use TCP/IP 哈工大计算机学院李全龙 Network Application Development Socket Programming 7
哈工大计算机学院 李全龙 Network Application Development Socket Programming 7 Conceptual interface specification The TCP/IP standards do not leave implementors without any guidance. They specify a conceptual interface: a set of procedures and functions. The conceptual interface defined by TCP/IP standards does not specify data representations or programming details; It merely provides an example of one possible interface that an OS can offer to application programs that use TCP/IP
Implementation of an API All implementations of a particular API appear the same to programmers: the API merely consists of a set of procedures( or functions)that an application program can call to establish communication or send and receive data In practice, the implementation of the api depends on the under lying system Sharing API code might reside in the computer's OS or it might reside in a region of memory devoted to shared libraries Win95/ 98 uses a shared lib scheme known as Dynamic Linked Library (DLL) 哈工大计算机学院李全龙 Network Application Development Socket Programming 8
哈工大计算机学院 李全龙 Network Application Development Socket Programming 8 Implementation of an API All implementations of a particular API appear the same to programmers: the API merely consists of a set of procedures ( or functions) that an application program can call to establish communication or send and receive data. In practice, the implementation of the API depends on the underlying system. Sharing API code might reside in the computer’s OS, or it might reside in a region of memory devoted to shared libraries. Win95/98 uses a shared lib scheme known as Dynamic Linked Library (DLL)
Implementation of an API Win95/98 p)(4p ppn App programs DLL containing socket interface procedures Socket API DLL containing TCP /IP software -TCP/IP functions Operating system Functions I/O functions 哈工大计算机学院李全龙 Network Application Development Socket Programming 9
哈工大计算机学院 李全龙 Network Application Development Socket Programming 9 Implementation of an API Win95/98 : Operating System Functions DLL containing TCP/IP software DLL containing socket interface procedures App1 App2 Appn TCP/IP functions …… App programs Socket API I/O functions
Implementation of an API Windows nt/2000/XP uses a hybrid scheme that includes both a dll and resident code App2 App pp programs DLL containing socket interface procedures Socket api TCP/IP functions Operating System Functions and io functions 哈工大计算机学院李全龙 Network Application Development Socket Programming 10
哈工大计算机学院 李全龙 Network Application Development Socket Programming 10 Implementation of an API Windows NT/2000/XP uses a hybrid scheme that includes both a DLL and resident code. Operating System Functions DLL containing socket interface procedures App1 App2 …… Appn App programs Socket API TCP/IP functions and I/O functions