Network Programming-Winsock

Source: Internet
Author: User
WinSock programming

Currently, Internet has become the world's largest TCP/IP network. Early websites were Unix machines, and a set of conventions known as the Berkeley plug-in became the standard for communications between Unix machines on the Internet using TCP/IP. Other operating systems also use TCP/IP for communication, which greatly promotes the development of the Internet.

Windows plug-in

The Winsock standard defines a DLL interface, usually Winsock. dll or wsock32.dll. No matter which DLL is installed on the machine, as long as the function name, parameter meaning, and final functions are the same, the applicationProgramYou can call these functions.
An important concept in Plug-in programming is a plug-in port. Each site on the Internet has a digital address called an IP address, which is usually separated by commas. Programs running on machines can communicate with other machines through plug-ins as needed.
When a request arrives at a machine, it carries a port number greater than 1024, indicating that the request is sent to that application.
Most plug-ins work based on connections: two programs form a connection at each end, and then send and receive data along the connection. Some applications tend to send data without connection, but the arrival of the data is not guaranteed.

Client/Server mode
In TCP/IP applications, how does one adopt the Client/Server mode.

On the client side, the TCP/IP application functions as follows:
1) Open the communication channel (apply for a socket) and connect to the reserved port of the server on the host. The port corresponds to the TCP/IP process of the server.
2) send a request message to the server, waiting for receiving a response.
3) The server receives the final response result, or closes the channel and terminates the client process when no request is received.

The action of the TCP/IP application on the server side is as follows:
1) Open the communication channel (apply for a socket) and notify the local host to receive client requests on a reserved port.
2) Wait for the customer's request to arrive at 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, close the communication link between the new process and the customer.
4) Continue waiting for client requests.
5) shut down the server process if you do not want to respond to the client request.
To sum up, server programs in TCP/IP applications must be started before the client process until the response to the client ends or is forcibly terminated.

Winsock1.1 uses the asynchronous selection mechanism to implement non-blocking communication. For non-blocking mode, the function is returned immediately after being called. After the transfer is complete, Winsock sends a pre-agreed message to the process.

Winsock is short for Windows Sockets and serves as an interface between windows and TCP/IP. We all know that TCP/IP plays an important role in the Internet. If you want to know about socket, Berkeley socket is a standard mode for programming TCP/IP in UNIX. The Design of Winsock is similar to that of WinSock, so that UNIX applications can be used on Windows platforms. However, there are some differences between the two. For example, winsocket utilizes some features of windows, which are not available for Unix.

Winsock is a DLL that runs under Windows 3.x, windows for workgroups, Windows NT, and Windows 95. Winsock. dll is an interface with TCP/IP, through which it is connected to the network. Show how it works:

Winsock. dll is actually the intermediate layer between the Winsock application and the TCP/IP protocol stack. Your application tells Winsock. dll what to do. Winsock. dll sends these commands to the TCP/IP protocol stack, which is sent to the network. However, you must note that the Winsock. dll used by the user must be consistent with the version number of TCP/IP. Do not call them winsocks in the future. They are the same. Therefore, if you are using Microsoft TCP/IP, you cannot use trumpet Winsock. Similarly, if you are using a slip connection and want to switch from Winsock of chameleon sampler to trumpet WinSock, you must delete Winsock. dll of chameleon and then install the new Winsock. dll.

For more information about Winsock network programming, see related information on the Internet.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.