Servers therefore have responsibilities:
Client responsibilities are much simpler:
In the spectrodaq framework, clients and servers are represented by the CSocket class. Sockets are used differently depending on whether or not the program is acting as a client or a server.
Server Sockets are wrapped in objects derived from the CServerConnectionEvent class. This class allows the programmer to set up a thread to listen for connection events on a socket which has been bound to listen for connection requests on a specified service or port. When connections arrive, the event calls CServerConnectionEvent::OnConnection passing it a CSocket which represents the connection to the client.
Application specific code can do whatever it wants at this time. Normally, if the connection is valid, the application code will use the socket object to create a CServerInstance derived object. CServerInstance encapsulates a request response protocol in which the server passively waits for client requests, reacts and replies to them.
In CServerInstance derived objects, CServerInstance::OnRequest is called whenever the client has a new request for the server. The server can read the request from the socket passed to OnRequest, process it and return information to the client by writing it along the socket.