In this article, Mitchell shows us how to implement our custom SARP protocol that we created yesterday. He uses PHP and its various socket functions to send SARP commands to our SARP server to both retrieve articles and add new articles to the servers Access database.
Building A Document Request Protocol Part 2/2 - Using SARP commands (Page 4 of 6 )
Now that we're connected and authenticated, we can use any of the SARP commands that we defined in the first article to retrieve the details of the brands and cars in our articles database. If your memory needs refreshing, here are the commands we've defined for our SARP server to respond to:
Let's retrieve the list of categories from our SARP server (remember that when our SARP server receives this command, it uses a select * from categories query to retrieve the category names from our Access database and forms them into a single string variable):
fputs($sarpHandle, "LIST CATEGORIES");
$sarpData = fgets($sarpHandle, 1024);
The data returned into the $sarpData variable looks like this:
1|BMW;4|Lamborghini;2|Mercedes-Benz;3|Porsche;
We can use PHP's explode function to separate each categories ID and name into an array:
$cats = explode(";", $sarpData);
echo "<h3>Available Content:</h3>";
Now that each category is separated into a separated index in the $cats array, we can loop through each category and use the "LIST ARTICLES" SARP command to retrieve the details of each article stored in our SARP servers Access database: