PHP
  Home arrow PHP arrow Page 3 - Building A Document Request Protocol Part ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building A Document Request Protocol Part 1/2
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-02-23

    Table of Contents:
  • Building A Document Request Protocol Part 1/2
  • Our protocol: SARP
  • The VB application
  • The ProcessCommands routine
  • Accepting new records from the client
  • Our VB App in action
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building A Document Request Protocol Part 1/2 - The VB application


    (Page 3 of 7 )

    To actually implement our protocol, we will create a Visual Basic application that will run on the server. Typically, a C, C++, or Perl application would be mapped to a port and execute whenever a connection request was attempted on that port, however to keep our article simple, we will use a VB6 app instead. Our application will run on the server, waiting for a connection request on port 2002.

    Our VB app will contain just one form, as well as a reference to the Winsock component. It looks like this:

    Our VB application

    The form is composed of a frame, list box, command button, and a Winsock control. The list box will display the details of all data being sent to and captured from the client. The close button will end the program.

    The Form_Load() event sets the Winsock controls protocol to TCP, and also sets its listening port to 2002:

    Private Sub Form_Load()

    wsSARP.Protocol = sckTCPProtocol

    wsSARP.LocalPort = 2002

    wsSARP.Listen

    End Sub


    When a connection request is detected, the ConnectionRequest event of the Winsock control is fired. It looks like this:

    Private Sub wssarp_ConnectionRequest(ByVal requestID As Long)

    wsSARP.Close

    wsSARP.Accept requestID



    End Sub


    Once the connection request has been accepted, the client is notified and can begin to send commands to the server. Our Visual Basic application will only respond to commands that adhere to those defined for our protocol, SARP. Shown below is a list of commands (along with their details) that make up our SARP protocol:

    LOGIN [user] [password]

    The client is attempting to login to the server. Returns a status number, as well as a message, depending on whether or not the login was successful.

    If the login was successful, then "102 Login OK" is returned. If it failed, then "103 Login Failed" will be returned.

    LIST CATEGORIES

    Returns a list of categories in the form of [category id] | [category name], with each new category separated by a semi-colon, for example:

    1|BMW;2|Mercedes-Benz;3|Porsche

    LIST ARTICLES [Category name]

    Returns a list of articles in the form of [article id] | [title] | [content] | [price], with each new article separated by a semi-colon, for example:

    1|BMW 318i|The 318i is the ideal family car. It's packed with style and sophistication, and comes in a wide range of colors and styles.|44000;

    ADD CATEGORY [Category name]

    Adds a new category to the categories table of our access database. If a category with [category name] already exists, then the category won't be added to the database.

    Returns "104 Category Added OK" when a new category is successfully added, or "105 Category Already Exists" if the category already exists in the categories table.

    ADD ARTICLE [Title] [Content] [Price] [Category Id]

    Adds a new article to the articles table of our access database. If an article with [title] already exists, then the article won't be added to the database. Because each variable is separated by a space, all spaces in its title and content must be replaced with an underscore, like this:

    ADD ARTICLE Carrera_Cabrolet This_is_a_nice_car 320000 3

    Returns "106 Article Added OK" on success, or "107 Article Already Exists" if the article already exists in the articles table.

    If any other command is received, then a blank line will be returned to the client indicating that the server didn't understand the command.

    When a client sends a command to the server, our Winsock control grabs that command in its DataArrival event:

    Private Sub wssarp_DataArrival(ByVal bytesTotal As Long)

    Dim strData As String

    Dim arrCommands() As String



    wsSARP.GetData strData

    lstDetails.AddItem "- Received Data """ & strData & """"



    ProcessCommands strData

    End Sub


    The command is then passed onto the ProcessCommands routine, which breaks the command up and determines what the client is trying to do. Let's look at the ProcessCommands routine next.

    More PHP Articles
    More By Mitchell Harper


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT