PHP
  Home arrow PHP arrow Page 2 - 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 2/2
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-02-24

    Table of Contents:
  • Building A Document Request Protocol Part 2/2
  • Connecting to our SARP server
  • Logging in
  • Using SARP commands
  • Adding new content using SARP commands
  • 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 2/2 - Connecting to our SARP server


    (Page 2 of 6 )

    PHP supports socket connections using either the TCP or UDP protocols. The fsockopen function creates a socket connection to another computer, allowing us to specify that computers IP address, required port, and even a connection time out. Its signature looks like this:

    int fsockopen (string hostname, int port [, int errno [, string errstr [, float timeout]]])

    Fsockopen returns 1 if the socket was created successfully, and 0 if it failed. The errno and errstr variables are passed in by reference, and will contain the details of an error if it occurs.

    To connect to our SARP server (remember that our "SARP server" is simply the VB app that we created in part one of this article running on the local machine), we can define some variables and use fsockopen to create a socket connection. Create a new file named sarp_test.php and save it in a directory that either Apache/IIS can process. Enter all of the code described over the next couple of sections into the file.

    <?php

    $xServer = "localhost";

    $xPort = 2002;

    $xTimeOut = 10;

    $xUser = "XUser";

    $xPass = "XPass";

    $sarpHandle = fsockopen($xServer, $xPort, &$errNo, &$errStr, $xTimeOut);

    if(!$sarpHandle)

    {

    die("Connection to \"$xServer\" failed.");

    }

    else

    {

    echo "Connected<br>";


    As you can see, we're creating a socket that binds to port 2002 on the server and has a timeout of ten seconds, meaning that if a connection to the server can't be established within ten seconds, then fsockopen will return false.

    If the socket couldn't be created, then the die() function outputs a connection failed message to the browser and terminates the script. On the other hand, if the connection succeeded, then we can place code inside of the else block to send data to and from that server.

    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 4 hosted by Hostway
    Stay green...Green IT