Server Code for an Internet Access Control Application
In the preceding article we dealt with the functional requirements of the server application as well as with the components that make up the server interface. In this article we will continue to build on the concepts that we discussed there and at the same time explore the code that runs the server application.
The "parsestring()" function is at its simplest a string handling function. It is responsible for parsing the strings that are sent between the server and client applications. This particular function will also be required by the client application according to the protocol requirements. Our custom protocol requires all communication to have the following format:
There are two delimiters, the colon(:) and the at(@) sign. Both of these are used to parse the communication into three parts. Below is the code that does the job. It is commented and easy to understand:
function ParseString(s : string; var Token1,Token2,Token3: string) :
P1,P2 : integer;
//store positions before and after the delimiters
P1 := Pos(':',s);
P2 := Pos('@',s);
//Test if both delimiters are present, in the right order and
//at least 1 char apart
if ((P1 > 0) and (P2 > 0) and (P2 > P1) and (Abs(P2-P1) > 1))
//store the different parts
Token1 := Copy(s,1,P1-1);
Token2 := Copy(s,P1+1,P2-P1-1);
Token3 := Copy(s,P2+1,Length(s)-P2);
Result := True; //valid string
else Result := False; //invalid string
The parsestring() function is of the utmost importance to the overall communication between the server and the client. Without this function there will be a complete breakdown of communication. So it is very important that you understand how this function works and improve on it.
There are a lot more procedures in the server code that we will look at, but unfortunately we will not look at all of them. In the next article we will cover three more procedures that also play a prominent role in the functional requirement of the server application. If at any stage anything is unclear to you about the code, please do not hesitate to contact me.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.