Windows Sockets: Background

Source: Internet
Author: User

This article describes the nature and usage of Windows Sockets. Other content includes:

  • Define the term "socket ".
  • The data type of the SOCKET handle.
  • Describes the purpose of a socket.

The Windows Sockets Specification defines a binary-compatible network programming interface for Microsoft Windows. Windows Sockets is based on the UNIX socket implementation in Berkeley Software Distribution (BSD, version 4.3), which was developed by the University of California at Berkeley. This specification includes BSD socket routines and extensions for Windows. By using Windows Sockets, applications can communicate on any network that complies with the Windows Sockets API. On Win32, Windows Sockets provides thread security.

Many network software vendors support Windows Sockets under network protocols, including Transmission Control Protocol/Internet Protocol (TCP/IP) and Xerox Network System (XNS) digital Equipment Corporation's DECNet protocol and Novell Corporation's Internet Packet Exchange Protocol/ordered Packet Exchange Protocol (IPX/SPX. Although the current Windows Sockets Specification defines the abstraction of TCP/IP Sockets, any network protocol can achieve Windows Sockets dynamic link library (DLL) by providing its own version) to meet the requirements of Windows Sockets. Examples of commercial applications written using Windows Sockets include X Windows Server, terminal simulator, and email system.

Note:The purpose of Windows Sockets is to abstract the basic network, so that you do not have to know much about the network, and your applications can run on any network that supports Sockets. Therefore, this document does not discuss the details of network protocols.

Microsoft basic library (MFC) supports programming using the Windows Sockets API by providing two classes. One of the classes isCSocketIt provides advanced abstraction to simplify network communication programming.

Windows Sockets specification "Windows Sockets: open interface for network computing in Microsoft Windows" is now version 1.1, it is developed by a large group of individuals and companies in the TCP/IP group. It is an open network standard and can be used for free. The socket programming model currently supports a "communication domain" that uses an Internet Protocol group (Internet Protocol Suite ). This specification can be obtained in Platform SDK.

Tip:Because sockets use Internet protocol groups, they are the preferred choice for applications that support Internet communication on the "Information Highway.

Socket Definition

A socket is a communication endpoint. It is an object used by a Windows Sockets application to send or receive data packets over the network. The socket has a type, is associated with a running process, and can have a name. Currently, sockets exchange data only with other sockets in the same "communication domain" of the Internet Protocol group.

Both sockets are bidirectional, which is a data stream that can communicate in both directions (Full Duplex) at the same time.

There are two types of available sockets:

  • Stream socket

    Stream sockets provide data streams without record boundaries, that is, byte streams. Byte streams ensure that they are delivered in the correct order without repetition.

  • Data PACKET socket

    The data PACKET socket supports record-oriented data streams, but it cannot be ensured to be delivered or in the sending order or not repeated.

"Ordered" means that data packets are delivered in the order of delivery. "Not repeated" means that a specific data packet can be obtained only once.

Note:In some network protocols (such as XNS), a stream can be record-oriented, that is, a record stream rather than a byte stream. However, in a more common TCP/IP protocol, the stream is a byte stream. Windows Sockets provides abstraction levels unrelated to basic protocols.

For more information about the above types and various Socket Application scenarios, see Windows Sockets: streaming socket and Windows Sockets: Data Reporting socket.

SOCKET Data Type

Each MFC socket object encapsulates the handle of a Windows Sockets object. The data type of the handle is SOCKET. The SOCKET handle is similar to the Windows HWND. The MFC socket class provides operations on the encapsulation handle.

The Platform SDK describes the SOCKET data type in detail.

Socket usage

The socket function is very powerful, at least in the following three communication contexts:

  • Client/server model.
  • Peer-to-peer network solutions, such as chat applications.
  • Call the Remote Procedure (RPC) by interpreting the message as a function call by the receiving application ).
Tip:The most suitable case for using an MFC socket is that when both ends of the communication are written at the same time: MFC is used at both ends. For more information about this topic (including how to manage communication with non-MFC applications), see Windows Sockets: byte sorting.

Related Article

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.