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 (Page 1 of 7 )
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. The Internet is the most common way to share data across two systems.
The Internet's transport protocol is TCP/IP, which actually moves the data (in the form of packets) from computer to computer, however there are also many other protocols that we use every day without even thinking about it: SMTP for mail, NNTP for UseNet news groups, UDP for file sharing programs such as Morpheus and Napster, etc.
If you're familiar with any of these protocols, then you will know that most are composed of simple, plain text commands, such as "GROUP alt.news.php" to tell a UseNet server that you'd like to connect to the alt.news.php news group.
Most protocols are standards, and are defined by the IETF (Internet Engineering Task Force) in individual RFC (request for comment) documents. If you've never worked with protocols before, then you might want to read over the RFC's for some of the more common protocols before continuing, just to get an idea of how they are composed:
Typically a client connects to a server through a socket. That particular socket on the server "listens" for client requests, and uses one pre-defined protocol. The client sends messages( confirming to the standards of that protocol) to the server, and the server responds with the required data, such as the body of an email message, the number of messages in a news group, etc. This continues until either the client or server closes the connection.
In this, the first article of a two part series, we're going to look at creating our own protocol. We will create a Visual Basic application that listens on a specified port for client connection requests. The client will be implemented in part two of this article, and it will be written entirely in PHP.
To test the source code and samples included with this article, you should be running a Windows PC with Visual Basic 6, MDAC 2.6 or later, PHP, and also Microsoft Access 2000. Don't worry if you don't have Access however, because the database we will be using is included with the support material at the end of this article.
You should also have an intermediate understanding of the Visual Basic programming language, Winsock, ADO, PHP, and PHP's various socket functions, including fsockopen, fputs, and fgets.