Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

TCP/IP client server programming

Modern TCP/IP network aware programs generally divide into two roles; clients and servers.

Servers therefore have responsibilities:

  1. Listen for connection requests from new clients on a specified "service port."
  2. Respond to work requests by existing, connected clients.

Client responsibilities are much simpler:

  1. Form a connection with a server
  2. Ask the server to do work, receive and analyze the server response.

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.


Generated on Thu Jan 6 16:58:46 2005 for Spectrodaq External Event Framework by  doxygen 1.3.9.1