The basic I/o functions in ANSI C Chapter 2: Socket Programming open: prepare a device or file for input or output Chapter goal: erations close: terminate use of a previously opened device Program interface to read: obtain data from an input device or file, and a Socket API write: transmit data from lication program's nory to an output device Socket programming model Iseek: move to a specific position in a file or device octl: control a device or software used to access it Socket API What is" socke↑"? Originally designed A socket is a virtual connection For BSD UNIX-Berkley Socket Interface between two applications To use with TCP/IP protocols Now Using a socket, two processes can communicate with each other The socket is the major communication Microsoft chose the socket interface as the primary API tool for Internet applications In Ms windows, WINSOCK A socket is bi-directional(full-duplex transmission A socket can be created dynamically Socket as a virtual connection between two processes Specifying a protocol interface Host A o support TCP/IP communicatio (nirmal cowe crion) Information Hiding ge neral ndsuese parameters to make TcP/IP communication The socket interface provides generalized functions that support network communication using many Socket functions refer to all TCP /IP protocols as a (plysical connection)3 哈工大计算机学院 李全龙 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. 哈工大计算机学院 李全龙 Network Application Development Socket Programming 14 Chapter 2: Socket Programming Chapter goal: Program interface to protocol Socket API Socket programming model 哈工大计算机学院 李全龙 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 哈工大计算机学院 李全龙 Network Application Development Socket Programming 16 What is “socket”? • A socket is a virtual connection between two applications • Using a socket, two processes can communicate with each other • The socket is the major communication tool for Internet applications • A socket is bi-directional (full-duplex) transmission • A socket can be created dynamically 哈工大计算机学院 李全龙 Network Application Development Socket Programming 17 Network Socket as a virtual connection between two processes (physical connection) Host B Process 2 Host A Process 1 Network Adapter Card Information Hiding Socket connection (virtual connection) 哈工大计算机学院 李全龙 Network Application Development Socket Programming 18 Specifying a protocol interface The designers must choose one of 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 in special case. The socket interface provides generalized functions that support network communication using many possible protocols. Socket functions refer to all TCP/IP protocols as a single protocol family. The functions allow the programmer to specify the type of service required rather than the name of a specific protocol