Socket api Chuan-Ming Liu Computer Science and Information Engineering Spring 2004, NTUT TAIWAN CS旧E.NTUT. TAWAN
CSIE, NTUT, TAIWAN 1 Socket API Chuan-Ming Liu Computer Science and Information Engineering Spring 2004, NTUT TAIWAN
Introduction Loosely specified protocol software interface Interface functionality Conceptual interface specification System calls Two basic approaches to network communication Basic lo functions in linux Using Linux l/o with TCP/IP CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 2 Introduction • Loosely specified protocol software interface • Interface functionality • Conceptual interface specification • System calls • Two basic approaches to network communication • Basic I/O functions in Linux • Using Linux I/O with TCP/IP
Loosely Specified Protocol TCP/IP protocol software resides in Os Routines in os for the interface between the applications and protocol are known as Application Program Interface(APl CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 3 Loosely Specified Protocol • TCP/IP protocol software resides in OS • Routines in OS for the interface between the applications and protocol are known as Application Program Interface (API)
Loosely Specified Protocol TCP/P designers design to operate in a multi-vendor environment avoid choosing any vendor's internal data representation avoid specifying the interface in terms of features available only on a single vendors Os The interface between TCP/IP and application is loosely specified CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 4 Loosely Specified Protocol • TCP/IP designers – design to operate in a multi-vendor environment – avoid choosing any vendor’s internal data representation – avoid specifying the interface in terms of features available only on a single vendor’s OS • The interface between TCP/IP and application is loosely specified
Loosely Specified Protocol Advantages Flexibility Tolerance Disadvantage designer can make the interface details different for each OS CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 5 Loosely Specified Protocol • Advantages – Flexibility – Tolerance • Disadvantage – designer can make the interface details different for each OS
Loosely Specified Protocol Only a few apls exist that permit an application to use TCP/IP protocol UNIX: socket APL, socket interface, or sockets MS Window: window sockets aT&T: acronym TLI CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 6 Loosely Specified Protocol • Only a few APIs exist that permit an application to use TCP/IP protocol – UNIX: socket API, socket interface, or sockets – MS Window: window sockets – AT&T: acronym TLI
TCP/IP Interface Functionality allocate local resources for communication Specify local and remote communication endpoints Initiate a connection(client) Send a datagram(client) Wait for an incoming connection(server) Send or receive data Determine when data arrives Generate urgent data CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 7 TCP/IP Interface Functionality • Allocate local resources for communication • Specify local and remote communication endpoints • Initiate a connection (client) • Send a datagram (client) • Wait for an incoming connection (server) • Send or receive data • Determine when data arrives • Generate urgent data
TCP/IP Interface functionality Handle incoming urgent data Terminate a connection gracefully Handle connection termination from the remote site abort communication Handle error conditions or a connection abort Release local resource when communication finishes CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 8 TCP/IP Interface Functionality • Handle incoming urgent data • Terminate a connection gracefully • Handle connection termination from the remote site • Abort communication • Handle error conditions or a connection abort • Release local resource when communication finishes
Conceptual Interface Specification The conceptual interface defined by the TCP/IP standards does not specify data representations or programming details; it merely provides an example of one possible API that an operation system can offer to application programs that use TCP/IP oS designers are free to implement as long as the functionality holds CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 9 Conceptual Interface Specification • The conceptual interface defined by the TCP/IP standards does not specify data representations or programming details; it merely provides an example of one possible API that an operation system can offer to application programs that use TCP/IP • OS designers are free to implement as long as the functionality holds
System Calls Mechanism that most operating systems use to transfer control between an applications and the operating system procedures Like function calls(for a programmer) CSIE NTUT TANAN
CSIE, NTUT, TAIWAN 10 System Calls • Mechanism that most operating systems use to transfer control between an applications and the operating system procedures • Like function calls (for a programmer)