What is“ socke↑"? A socket is a virtual connection between two applications Using a socket two processes can communicate with each other The socket is the ma jor communication tool for Internet applications A socket is bi-directional (full-duplex) transmission A socket can be created dynamically 哈工大计算机学院李全龙 Network Application Development Socket Programi mIng
哈工大计算机学院 李全龙 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
Socket as a virtual connection between two processes Host a Host B Socket connection virtual connection Process Process 2 Information Hiding Network Adapter Card Network (physical connection) 哈工大计算机学院李全龙 Network Application Development Socket Programming 17
哈工大计算机学院 李全龙 Network Application Development Socket Programming 17 Socket as a virtual connection between two processes Network (physical connection) Host B Process 2 Host A Process 1 Network Adapter Card Information Hiding Socket connection (virtual connection)
Specifying a protocol interface The designers must choose one of two broad approaches: Define functions specifically to support TCP/II 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. 哈工大计算机学院李全龙 Network Application Development Socket Programming 18
哈工大计算机学院 李全龙 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 t o 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
Socket abstraction In most OS, an application that needs to perform I/o asks the os to open a file OS responds by creating a file descriptor Descriptor table (one per process) 0: Internal data structure for file o Internal data structure for file 1 Internal data structure for file 2 3: Internal data structure for file 3 Operating system 哈工大计算机学院李全龙 Network Application Development Socket Programming 19
哈工大计算机学院 李全龙 Network Application Development Socket Programming 19 Socket abstraction In most OS, an application that needs to perform I/O asks the OS to open a file. OS responds by creating a file descriptor. . 0: Internal data structure for file 0 . 1: Internal data structure for file 1 . 2: Internal data structure for file 2 . 3: Internal data structure for file 3 . . . Descriptor table (one per process) Operating System
Socket abstraction the socket interface adds a new abstraction for network communication-socket. OS abstraction(not hardware Created dynamically Persists only while application runs Referenced by a socket descriptor 哈工大计算机学院李全龙 Network Application Development Socket Programming 20
哈工大计算机学院 李全龙 Network Application Development Socket Programming 20 Socket abstraction The socket interface adds a new abstraction for network communication-socket. OS abstraction (not hardware) Created dynamically Persists only while application runs Referenced by a socket descriptor