Windows Sockets is an open interface for Network Programming under Microsoft Windows. The specification, header file, and WinSock API library are all that is needed to develop
Windows Sockets applications.
Windows Sockets (WinSock) clearly defines the division of labor between the network application and the network protocol stack: The application provides the content, while the network protocol stack provides the delivery.
WinSock also provides binary compatibility. An executable requires no changes when moved from one network system vendor to another, or between operating system platforms.
The Windows Sockets API WSA consists of a collection of functions, data structures and conventions. WSA provides standard access to the network services of an underlying protocol stack to any Windows application.
WinSock API is a programmatic plug into the network. You can plug any electrical appliance (application) into an electric socket (socket) in any house, and it will work no matter how the electricity is generated (coal, water, nuclear, etc.) In other words, you can run any TCP/IP network application on any WinSock implementation, no matter what media it runs over – Ethernet, Token Ring, Serial Line – or what company provides the TCP/IP protocol stack.
The Open Systems Interconnect (OSI) is a network reference model that presents an overview of all network systems. It reduces the complex subject of networking into its essential components, and illustrates how these components interact with each other in a common framework.
The OSI is a fundamental model, from which almost all other network concepts derive. The components and the organization of the OSI is shown below:
Layer # | Layer Name | Description |
Upper Layer | ||
7 | Application | Provides user interface and other functionality to complete the application - file transfer, e-mail, etc. |
6 | Presentation | Formats data - compresses/decompresses, encrypts/decrypts, convert between different representations. |
5 | Session | Opens a session (virtual connection) between two network hosts, controls the session, and closes it. |
Lower Layer | ||
4 | Transport | Transfers data reliably or unreliably. |
3 | Network | Addresses packets and routes to provide end-to-end communications between two network hosts. |
2 | Data Link | Creates and controls the physical links of communication between two endpoints and multiplexes links competing for a shared interface. |
1 | Physical | Network card / chip and cables. |
In the Windows Sockets model, we call the upper layer the Winsock application, and the lower layer the network system. The term protocol stack is a synonym for protocol suite, and alludes to the stack of boxes in the OSI model
In the OSI mode, the work flows downward. Each layer uses the services of the next layer down by using its interface. A layer’s interface provides a set of well-defined functions to make its services available. However, note that failures bubble up in the OSI model.
A WinSock application has a modular architecture as presented below:
Note how the upper layers of the OSI model are referred to as Windows Sockets Application, while the lower layers form the Network System. The WinSock API (WSA) sits between the two. WSA provides access to the Network System, and the WinSock Applications uses WSA services to send and receive information.
Data is an arbitrary collection of bytes, whereas information has structure and meaning. Each layer in the OSI deals with its own information, and anything it receives from a layer above is considered formless and meaningless data. The Network System in the WinSock Network Model sends and receives data as requested by the WinSock Application. This data is meaningful only to the application, but not to the network system. When the application sends a block of information that has a specific length, format and meaning, the network system may fragment it arbitrarily and re-assemble it at the other end. How the data is treated depends on the network system, but in any case, the network system delivers data without regard to content or meaning.
An application protocol defines the rules governing communication between network applications. Two applications must have a protocol in order to communicate, because it defines what the applications expect from each other.
The WinSock Network Model is a simplified version of the OSI Model. However, the individual OSI functionality still exists in the WinSock Network Model at a conceptual level. An email program is used to illustrate what each layer does in practical terms.
Note how each layer adds information to the data the session layer originally asked to be sent
Note that the boxes in the OSI model and the WinSock model imply a modular architecture which allows for mixing and matching components. Each layer is a black box where the implementation details may change, but the interface and the services remain the same. The following key figure illustrates some of the key points of OSI:
The following two figures show how a WinSock application and the network system on one computer relate to another computer. The router is included to make the illustration more realistic (A router is used to connect different network medias – Ethernet to Token Ring, etc. By definition a network always has at least one
router):
In the figure above, the black arrows denote conversation between peer layers. Peer layers talk to each other using the same protocol, which is a precise set of rules for communication. The peer communication is only conceptual and the blue line shows how information actually flows. The following figure shows how communication between peer layers actually takes place:
A sending application passes its information to the layer below, which adds its own information and passes it to the next layer down. Think of this process as putting an envelope inside another, and into another and so on (blue arrows in the first figure)
On the receiving end, each layer removes its information, interprets it (conversation between peer layers), and responds according to protocol. It then passes the remaining data to the next layer up and so.
The Windows Sockets API is protocol-independent.. The API provides access to the services in a protocol suite. Different protocols provide the same services.
If you have two networked PCs and you want them to talk to each other, the only time you need to use the same API is if you’re planning on using the same source code. You always need to the same protocol suite on both PCs.
As these figures show, for two networked PCs to communicate, APIs need not be the
same but protocols must be: