tailieunhanh - Networking and Network Programming 2 TCP/IP phần 4

Hai chương trước đó cho thấy làm thế nào để khởi tạo thư viện WinSock và làm thế nào để giải quyết tên máy chủ và dịch vụ. Chương này thảo luận về các chức năng WinSock còn lại cần thiết để làm cho một ứng dụng nối mạng thật sự hữu ích. | Part II Basics of WinSock Programming The preceding two chapters show how to initialize the WinSock library and how to resolve host names and services. This chapter discusses the remaining WinSock functions necessary to make a truly useful networked application. Among these functions are the following socket to create an end-point of communication bind to give the end-point a name listen to listen for incoming connections accept to accept a connection send and sendto to send data and recv and recvfrom to receive data. Figure shows the flow of WinSock function calls for a client and server using TCP. Figure shows a similar flow of WinSock function calls but this time for a client and server using UDP. FIGURE . Client server WinSock function flow using TCP. Server Client socket Create the Socket bind Give the Socket a Name listen new socket to be created while the socket Create the Socket T connect Connect to the Server original socket continues to wait for new connections send recv send recv Send and Receive Data closesocket Close the Connection closesocket Close the Connection FIGURE . Client server WinSock function flow using UDP. Server Client Chapter 7 Socket Functions socket Create the Socket I bind Give the Socket a Name sendto recvfrom Send and Receive Data z closesocket Close the Connection socket Create the Socket . I sendto recvfrom Send and Receive Data T closesocket Close the Connection Creating an End-Point of Communication The socketo function creates an end-point of communication called a socket. Its function prototype is as follows SOCKET PASCAL FAR socket int af int type int protocol af specifies the address family this socket uses. WinSock supports only the AF_INET or Internet address family format. type is the type specification for the socket. For most applications this value is either SOCK_STREAM for a connection-oriented byte stream or SOCK_DGRAM for connectionless datagram service. protocol is the particular protocol to use .

TỪ KHÓA LIÊN QUAN