If you’ve ever visited an Internet café, you've noticed that there is usually a timer on the screen that tells you how much time you have left to use the Internet. In this series of articles we will discuss both the underlying architecture of such an application as well as the code involved, culminating in creating an example application.
Building an Internet Access Control Application - The Protocol (Page 2 of 4 )
The indy components that we will be using make it easy to create a custom protocol. We will be using two components, called idCmdTCPClient and idCMdTCPServer, that provide the medium for us to create our own communication protocol. Because we’ve looked at the requirements for the applications involved, we already have an idea of how the communication should go.
First, the Client Application contacts the server application and connects, giving its name. For example, if the client computer is called Joe Blogg, then it will try to give that name to the server application. At this point the server should actually check to see if the name already exists and then send an appropriate error message back. This is of course dependent on whether you are actually going to use this application for the purpose that it is designed (to control access to the Internet), in which case all the computers that are connected to the network will already have unique names. Also with the name is included another piece of status information, which tells the server that the connecting client is available. So the total sum of the communication sent by the client should be something like this:
The second step involves the Server. Since the communication from the client will be two parts (name and status), the server takes that communication and breaks it up into the individual two parts. At the same time the server takes the IP address of the connecting client as well as the time of connecting. So something like this takes place on the server:
server: name OK
If not OK then
send appropriate message to client and disconnect
Finally, once the connection is successful then all communication from here on in will be initiated by the server application. For example, to tell a client to grant access for ten minutes, the server would send the following communication:
The above statement says: activate the computer that has the name "workstation" for ten minutes. The client application receives this string, breaks it up into three pieces, and gives it to the relevant functions for further processing.