source: trunk/instant_messenger/inc/class.Socket.inc.php @ 20

Revision 20, 2.3 KB checked in by niltonneto, 17 years ago (diff)

Inclusão do módulo Mensageiro Instantâneo no CVS.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /************************************************************
3         *      Classe Jabber - Expresso                                                                *
4         *  ------------------------------------------------------- * 
5         *  Com Autenticação no Servidor Jabber com Tls                         *       
6         *  Rodrigo Souza - rodsouza@celepar.pr.gov.br                          *
7         *      Alexandre Correia - alexandrecorreia@celepar.pr.gov.br  *
8         ************************************************************/
9
10class Socket
11{
12        private $socket;
13               
14        protected final function open($pRemoteSocket, $pTimeOut = 1, $pBlockingMode = 0 )
15        {
16                if ( ($this->socket = stream_socket_client($pRemoteSocket, $errno, $errstr)) )
17      {
18         //$this->socket = stream_socket_client($pRemoteSocket, $errno, $errstr);//, 1, STREAM_CLIENT_CONNECT+STREAM_CLIENT_PERSISTENT);
19         //stream_set_write_buffer($this->socket, 0);
20         stream_set_blocking($this->socket, $pBlockingMode);
21         stream_set_timeout($this->socket, 1);//$pTimeOut);
22         return true;
23      }
24
25      return false;
26        }
27
28        protected final function close()
29        {
30                if ( $this->isConnected() )
31                        return fclose($this->socket);
32                else
33                        return false;
34        }
35
36        protected final function read($pLine = false, $pEnding = false, $pLength = 4096)
37   /*
38    *
39    * the jabber's documentation recommends to read
40    * the packages of socket with size of 4096 (2^12) KB
41    *
42    ******************************************************
43    *
44    * a documentação do jabber recomenda ler
45    * os pacotes do socket com tamanho de 4096 (2^12) KB
46    *
47    */
48        {
49                if ( !$this->isConnected() )
50         return false;
51
52      if ( !$pLine )
53         return @stream_get_line($this->socket, $pLength);
54
55      $retorno = NULL;
56      do
57      {
58         $line = NULL;
59         $line = @stream_get_line($this->socket, $pLength);
60         if ( $line != NULL )
61         {
62            $retorno .= $line;
63         }
64      }
65      while ( $line != NULL );
66
67      return $retorno;
68        }
69
70        protected final function write($pData)
71        {
72                if ( $this->isConnected() )
73                        return fwrite($this->socket, $pData);
74                else
75                        return false;
76        }
77
78        protected final function isConnected()
79        {
80                if(is_resource($this->socket))
81                        return true;
82                else
83                        return false;   
84        }
85       
86        protected final function returnSocket()
87        {
88                return $this->socket;   
89        }
90
91        protected function __destruct()
92        {
93                        //fclose($this->resource);
94        }
95}
96?>
Note: See TracBrowser for help on using the repository browser.