正在加载图片...
Socket abstraction Socket abstraction In most OS, an application that needs to perform I/0 asks the Os to open a file. a The socket interface adds a new OS responds by creating a file descriptor. abstraction for network communication -socket nternal data structure for file 0 Os abstraction(not hardware rnal data structure for Internal data structure for file 2 Internal data structure for file 3 Persists only while application runs a Referenced by a socket descriptor Socket Descriptor Creating a Socket a Small integer desc= socket(protofamily, type, proto) m One per active socket a Used in all operations on socket Application calls socket function a Generated by OS when socket created OS returns descriptor for socket Only meaningful to application/process Descriptor valid until application closes hat owns socket socket or exits In UNIX, integrated with file descriptors Common: protofamily PF_INET. The Windows OS keeps a separate table of type =SOCK_STREAM, SOCK_DGRAM socket descriptors for each process or s Socket Functionality Using sockets Socket completely general aA socket used by a server: passive socket Can be used A socket used by a client: active socket By client The difference lies in how applications use server them With a co transport protocol With a CL transport protocol a The sockets are created the same way initially To send data receive data or both Large set of operations4 哈工大计算机学院 李全龙 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 哈工大计算机学院 李全龙 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 哈工大计算机学院 李全龙 Network Application Development Socket Programming 21 Socket Descriptor „ Small integer „ One per active socket „ Used in all operations on socket „ Generated by OS when socket created „ Only meaningful to application/process that owns socket „ In UNIX, integrated with file descriptors „ The Windows OS keeps a separate table of socket descriptors for each process 哈工大计算机学院 李全龙 Network Application Development Socket Programming 22 Creating a Socket „ Application calls socket function „OS returns descriptor for socket „ Descriptor valid until application closes socket or exits „ Common: protofamily = PF_INET, type = SOCK_STREAM,SOCK_DGRAM or SOCK_RAW desc = socket(protofamily,type,proto); 哈工大计算机学院 李全龙 Network Application Development Socket Programming 23 Socket Functionality „ Socket completely general „ Can be used „ By client „ By server „With a CO transport protocol „With a CL transport protocol „ To send data, receive data, or both „ Large set of operations 哈工大计算机学院 李全龙 Network Application Development Socket Programming 24 Using sockets „ A socket used by a server: passive socket „ A socket used by a client: active socket „ The difference lies in how applications use them „ The sockets are created the same way initially
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有