Winsock programming

zhaozj2021-02-11  194

WINSOCK programming Author: Du Lijun Published: 2001/01/15

Thesis:

The Winsock standard defines a DLL interface, usually called Winsock.dll or WSOCK32.DLL. Regardless of which DLL installed on the machine, as long as the name, parameter meanings, and the final function is the same, the application can call these functions.

text:

Winsock Programming Currently, Internet has become the world's largest TCP / IP network. Early sites are UNIX machines, a set of conventions called the Berkeley jack becoming a standard for communicating between the UNIX machines on the Internet. Other operating systems are also communicating with TCP / IP, which greatly promotes the development of the Internet. The Windows socket Winsock standard defines a DLL interface, usually called Winsock.dll or WSOCK32.DLL. Regardless of which DLL installed on the machine, as long as the name, parameter meanings, and the final function is the same, the application can call these functions. An important concept in the socket program is the port of a socket. Every site on the Internet has a digital address called an IP address, usually four numbers separated by commas. Programs running on the machine can communicate with other machines as you want to use. When the request arrives at the machine, carry a port number, a number of greater than 1024, which indicates that this request is to the application. The operation of the most socket is based on the connection: two programs form a connection in each end, and then send data along the connection. Some applications tend to send no connection, but the arrival of these data is not guaranteed. Client / Server Mode How to use client / server mode in TCP / IP applications. In the client side, the TCP / IP application function is as follows: 1) Open the communication channel (apply for a socket) and connect to the server's retention port that corresponds to the server's TCP / IP process. 2) Send a request message to the server and wait for the reception answer. 3) Receive the final response result from the server side, or turn off the channel and terminate the client process when no longer requests. One side of the server, TCP / IP application actions are as follows: 1) Open the communication channel (apply for a socket), notify the local host to receive client requests at a reserved port. 2) Waiting for the customer request to reach the specified port. 3) Receive the request, start a new process to process the user request, and release the old process to respond to the new customer request, once the service is complete, turn off the new process and the customer's communication link. 4) Continue waiting for the client request. 5) If you do not want to respond to the client request, turn off the server process. In summary, the server program in the TCP / IP application must be started before the client process until the response to the client is ended or forced to terminate. The Winsock1.1 is implemented by an asynchronous selection mechanism. For non-blocking methods, the function returns immediately after the function is called, and when the transfer is completed, send a prior approximate message to the process by Winsock. The Winsock system calls Winsock provides more than 100 communication functions, but there must be not used. The following table lists several functions that are often used. Asynchronous selection mechanisms Winsock provides asynchronous selection functions WSAAsYNSELECT () to implement non-blocking communication. When the WSaasynselect () function features the network event with the Winsock message, register some user-interested web events. When these registered network events occur, the window function of the application will receive the message. The function prototype is as follows: int WSAASYNSELECT (Socket S, HWND, Unsigned INT WMSG, Long Long LEVEN) Function Description: Inform the Windows Socket DLL to submit a message WMSG to the window hWnd when detecting the network event LEVEN that appears on the socket S. Levent: The registered network event.

转载请注明原文地址:https://www.9cbs.com/read-4992.html

New Post(0)