Win Sockets

interface to Windows sockets

1.0 Concept

Fig 1. Sockets Model
Sockets are an operating system facility for sending streams of bytes through the tcp stack to another process or another machine. Their behavior is affected by buffers owned by each socket receiver.
If the sender sends N bytes, then: Sockets don't know about any data structure other than streams of bytes. So to send a message you must frame it's bytes with some additional decoration so the receiver can detect when an entire message has been received.
Also, since both sending and receiving are allowed on the same socket connection, some talk protocol is needed. Without that, both ends may send, eventually resulting in deadlock. Similarly, if both receive then buffers on both ends will empty, resulting again in deadlock.
The socket library provided in this repository provides means to simplify handling both problems. See the Resources listed below for ways to fully handle them.

2.0 Design

Fig 2. Sockets Class Diagram
Sockets-Windows provides four classes: Socket, SocketConnecter, SocketListener, and SocketSystem. An instance of Socket is created by the SocketListener when it establishes a connection. Listener creates a thread, passing it a client handler object and the new socket. Clients use SocketConnecter to establish a connection with a listener and to communicate with the remote socket.
Each program that uses Sockets must declare an instance of SocketSystem that loads the windows socket library on construction and unloads on destruction.

3.0 Resources

Win32Sockets.pdf
Discusses how Win32 Sockets operate.
CommunicationChannel.pdf
This document describes how sockets are used to build a reliable message-based asynchronous communication channel.
CppCommWithFileXfer
This repository holds code that uses these techniques.