SOAP--Server
[ class tree: SOAP--Server ] [ index: SOAP--Server ] [ all elements ]

Source for file TCP.php

Documentation is available at TCP.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more   |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: TCP.php,v 1.1 2003/04/08 06:21:53 shane Exp $
  20. //
  21.  
  22. require_once 'SOAP/Server.php';
  23. /**
  24. *  SOAP_Server_TCP
  25. * SOAP Server Class
  26. *
  27. * implements TCP SOAP Server
  28. * http://www.pocketsoap.com/specs/smtpbinding/
  29. *
  30. * class overrides the default HTTP server, providing the ability
  31. * to accept socket connections and execute soap calls.
  32. *
  33. * TODO:
  34. *   use Net_Socket
  35. *   implement some security scheme
  36. *   implement support for attachments
  37. *
  38. @access   public
  39. @version  $Id: TCP.php,v 1.1 2003/04/08 06:21:53 shane Exp $
  40. @package  SOAP::Server
  41. @author   Shane Caraveo <shane@php.net>
  42. */
  43. class SOAP_Server_TCP extends SOAP_Server {
  44.     var $headers = array();
  45.     var $localaddr;
  46.     var $port;
  47.     var $listen;
  48.     var $reuse;
  49.     
  50.     function SOAP_Server_TCP($localaddr="127.0.0.1"$port=10000$listen=5$reuse=TRUE)
  51.     {
  52.         parent::SOAP_Server();
  53.         $this->localaddr = $localaddr;
  54.         $this->port = $port;
  55.         $this->listen = $listen;
  56.         $this->reuse = $reuse;
  57.     }
  58.  
  59.     function run()
  60.     {
  61.         if (($sock socket_create (AF_INETSOCK_STREAM0)) < 0{
  62.             return $this->_raiseSoapFault("socket_create() failed: reason: " socket_strerror ($sock));
  63.         }
  64.         if ($this->reuse &&
  65.             !@socket_setopt($sock,SOL_SOCKET,SO_REUSEADDR,1)) {
  66.             return $this->_raiseSoapFault("socket_setopt() failed: reason: ".socket_strerror(socket_last_error($sock)));
  67.         }        
  68.         if (($ret socket_bind ($sock$this->localaddr$this->port)) < 0{
  69.             return $this->_raiseSoapFault("socket_bind() failed: reason: " socket_strerror ($ret));
  70.         }
  71.         # print "LISTENING on {$this->localaddr}:{$this->port}\n";
  72.         if (($ret socket_listen ($sock$this->listen)) < 0{
  73.             return $this->_raiseSoapFault("socket_listen() failed: reason: " socket_strerror ($ret));
  74.         }
  75.         
  76.         do {
  77.             $data = NULL;
  78.             if (($msgsock socket_accept($sock)) < 0{
  79.                 $this->_raiseSoapFault("socket_accept() failed: reason: " socket_strerror ($msgsock));
  80.                 break;
  81.             }
  82.             # print "Accepted connection\n";
  83.             while ($buf socket_read ($msgsock8192)) {
  84.                 if (!$buf trim($buf)) {
  85.                     continue;
  86.                 }
  87.                 $data .= $buf;
  88.             }
  89.             
  90.             if ($data{
  91.                 $response $this->service($data);
  92.                 # write to the socket
  93.                 if (!socket_write($msgsock$responsestrlen($response))) {
  94.                     return $this->_raiseSoapFault('Error sending response data reason '.socket_strerror());
  95.                 }
  96.             }
  97.             
  98.             socket_close ($msgsock);
  99.         while (true);
  100.         
  101.         socket_close ($sock);
  102.     }
  103.     
  104.     function service(&$data)
  105.     {
  106.         # XXX we need to handle attachments somehow
  107.         return $this->parseRequest($data,$attachments);
  108.     }    
  109. }
  110.  
  111. ?>

Documentation generated on Mon, 11 Mar 2019 13:59:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.