Disparate systems communicate with each other using protocols. A protocol is a set of rules that governs the transmission of data between two independent systems. If you're familiar with protocols, then you will know that most are composed of simple, plain text commands. In this article Mitchell shows us how to create a protocol and implement it as a server using Visual Basic and Winsock.
Building A Document Request Protocol Part 1/2 - Our protocol: SARP (Page 2 of 7 )
We are going to create a protocol that will be used to request and modify a set of categories and articles. The protocol will be called Simple Article Request Protocol, or SARP for short.
The protocol will, in some ways be similar to the NNTP protocol. Here’s a list of the functions that our protocol will implement:
Retrieving a category name
Retrieving a list of articles based on a category ID
Adding a new category
Adding a new article under a specific category
The protocol will expect simple text requests for its commands, and will operate on port 2002 by default. The categories and articles will be stored in an Access 2000 database, and the actual implementation of the protocol will be carried out using Visual Basic and the Winsock control.
Because the source code and accompanying program files for this article are rather large, we will only look at the most important parts of our implementation. You can download all of the code from the support material link, which is on the conclusions page.
Let's start by looking at the Access database that will hold our two tables: categories and articles:
The id field of the categories table links it to the articles table by the catId field. The fields in the tables should be self-explanatory. We will fill our database with the brands and models of luxury cars, as shown below:
Our Access database will be responsible for providing our Visual Basic application with the data so that it can fulfill its SARP protocol requests to the client. Let's look at the Visual Basic application now.