Implementation of an API Other implementations are possible OS with no DLL support, all the procedures in API are art o f os A programmer can create an application program that uses the socket aPi without knowing how the api is implemented The programmer makes procedure calls which may evoke procedures that are linked into the application procedures in DLL, or procedures in OS ApP1(App App pp programs Socket api Operating system Functions TCP/IP functions and i/o functions 哈工大计算机学院李全龙 Network Application Development Socket Programming 11
哈工大计算机学院 李全龙 Network Application Development Socket Programming 11 Implementation of an API Other implementations are possible. OS with no DLL support, all the procedures in API are part of OS. A programmer can create an application program that uses the socket API without knowing how the API is implemented. The programmer makes procedure calls which may invoke procedures that are linked into the application, procedures in DLL, or procedures in OS. Operating System Functions App1 App2 …… Appn App programs Socket API, TCP/IP functions and I/O functions
Two basic approaches to network communication a The designer invents entirely new procedures calls that applications use to access TCP/IP Windows uses this method a the designer attempts to use conventional I/0 calls to access TCP/IP Unix uses this method 哈工大计算机学院李全龙 Network Application Development Socket Programming 12
哈工大计算机学院 李全龙 Network Application Development Socket Programming 12 Two basic approaches to network communication The designer invents entirely new procedures calls that applications use to access TCP/IP. Windows uses this method. The designer attempts to use conventional I/O calls to access TCP/IP. Unix uses this method
The basic I/o functions in ANSI C open: prepare a device or file for input or output operations close: terminate use of a previously opened device or file read: obtain data from an input device or file, and place it in the application program's memory write: transmit data from the application program's memory to an output device or file Iseek: move to a specific position in a file or device ioctl: control a device or software used to access it 哈工大计算机学院李全龙 Network Application Development Socket Programming 13
哈工大计算机学院 李全龙 Network Application Development Socket Programming 13 The basic I/O functions in ANSI C open: prepare a device or file for input or output operations. close: terminate use of a previously opened device or file. read: obtain data from an input device or file, and place it in the application program’s memory. write: transmit data from the application program’s memory to an output device or file. lseek: move to a specific position in a file or device. ioctl: control a device or software used to access it
Chapter 2: Socket Programming Chapter goal: Program interface to rotocol Socket API Socket programming model 哈工大计算机学院李全龙 Network Application Development Socket Programming 14
哈工大计算机学院 李全龙 Network Application Development Socket Programming 14 Chapter 2: Socket Programming Chapter goal: Program interface to protocol Socket API Socket programming model
Socket API Originally designed For bsd UniX Berkley Socket Interface To use with TCP/IP protocols ■NoW Industry standard Available on many operating systems Microsoft chose the socket interface as the primary aPI In Ms windows WINSOCK 哈工大计算机学院李全龙 Network Application Development Socket Programming 15
哈工大计算机学院 李全龙 Network Application Development Socket Programming 15 Socket API Originally designed For BSD UNIX-Berkley Socket Interface To use with TCP/IP protocols Now Industry standard Available on many operating systems Microsoft chose the socket interface as the primary API. In MS Windows, WINSOCK