Public Method Details |
setBlocking |
|
public bool setBlocking( [ string $mode ], string $connection )
|
| |
Sets whether the socket connection should be blocking or
not. A read call to a non-blocking socket will return immediatelyif there is no data available, whereas it will block until thereis data for blocking sockets.note I: nonblocking mode not supported on win (php404). so until it'savailable, you cannot set this to blocking on win.note II: if the 2nd param $connection is given, this method is used static.the return value stays the same, no need to pass $connection by reference.note III: non-blocking sockets waste alot of cpu. take care. but some thingsreally cannot be done without.
|
| Parameter |
|
| string |
$mode |
= >>TRUE,<< |
|
true for blocking sockets, false for nonblocking. default is TRUE. |
|
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
bool true if it was possible to set, false if it failed. (fails to set blocking on win) |
|
isBlocking |
|
public bool isBlocking( )
|
| |
Find out if the socket is in blocking mode.
|
| Returns |
bool the current blocking mode. |
|
getState |
|
public int getState( )
|
| |
Get the current state of the socket.
one ofdefine('BS_SOCKETCLIENT_DISCONNECTED', 0);define('BS_SOCKETCLIENT_CONNECTED', 1);define('BS_SOCKETCLIENT_SENT', 2);define('BS_SOCKETCLIENT_REQUEST_SENT', 3);define('BS_SOCKETCLIENT_GOT_REPLY', 4);define('BS_SOCKETCLIENT_GOT_REPLY_HEADER', 5);define('BS_SOCKETCLIENT_GOT_REPLY_CONTENT', 6);hint. (bool)TRUE=connected, FALSE=disconnectedit's possible that this is set to connected but the connection expiredor something else happened... it's the "should be" state.
|
| Returns |
int the current state. |
|
setState |
|
public void setState( int $state )
|
| |
Set the current state of the socket.
one ofdefine('BS_SOCKETCLIENT_DISCONNECTED', 0);define('BS_SOCKETCLIENT_CONNECTED', 1);define('BS_SOCKETCLIENT_SENT', 2);define('BS_SOCKETCLIENT_REQUEST_SENT', 3);define('BS_SOCKETCLIENT_GOT_REPLY', 4);define('BS_SOCKETCLIENT_GOT_REPLY_HEADER', 5);define('BS_SOCKETCLIENT_GOT_REPLY_CONTENT', 6);
|
| Parameter |
|
| int |
$state |
|
|
please use the constant. |
|
| Returns |
void |
|
connect |
|
public mixed connect( string $host, int $port, [ string $persistent, integer $timeOut, string $blocking, string $return ] )
|
| |
Connect to the specified port.
If called when param $return is set to 'bool' and the socket is alreadyconnected, it disconnects and connects again.unless called with param $return='resource', these object vars areoverwritten/updated:$this->host $this->_connection$this->port $this->_state$this->timeOut$this->persistent$this->_blocking
|
| Parameter |
|
| string |
$host |
|
|
like 'your.server.com' or an ip address like '111.111.111.111'. |
|
|
| int |
$port |
|
|
the tcp port number. |
|
|
| string |
$persistent |
= >>FALSE,<< |
|
default is FALSE. |
|
|
| integer |
$timeOut |
= >>0<< |
|
default is 0 (which means don't specify one). |
|
|
| string |
$blocking |
= >>TRUE,<< |
|
default is TRUE. see $this->setBlocking(). |
|
|
| string |
$return |
= >>'bool'<< |
|
one of 'bool' (default) or 'resource'. |
|
| Returns |
mixed depends on param $return. if set to 'bool' -> bool true on success, if set to 'resource' -> the resouce. on failure see throw. |
| Throws |
bs_exception |
|
reconnect |
|
public bool reconnect( )
|
| |
Reconnect to the current host with the current settings - if possible.
|
| Returns |
bool true on success, false on failure or if not capable. |
|
disconnect |
|
public void disconnect( string $connection )
|
| |
Disconnects from the peer, closes the socket.
if the param $connection is given, this method is used static.
|
| Parameter |
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
|
eof |
|
public bool eof( string $connection )
|
| |
if the param $connection is given, this method is used static.
|
| Parameter |
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
bool |
|
readLine |
|
public mixed readLine( [ string $removeCrlf ], string $connection )
|
| |
Read from the connection until we got a full line, then return it.
if the param $connection is given, this method is used static.
|
| Parameter |
|
| string |
$removeCrlf |
= >>TRUE,<< |
|
if the carriage return/line feed (or lf, whatever there is) at the end should be removed or not. default is TRUE. |
|
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
mixed string the line or NULL on eof
@throw NULL on an error. we cannot distinguish between error and eof :((( read comment in the code. |
| See Also |
gets(), read(), readAll() |
|
readAll |
|
public string readAll( string $connection )
|
| |
Read until the socket closes.
CAUTION: this method will not exit if the socket is in blocking modeuntil the socket closes.if the param $connection is given, this method is used static.
|
| Parameter |
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
string all data until the socket closes. |
| See Also |
gets(), read(), readLine() |
|
gets |
|
public string gets( int $size, string $connection )
|
| |
Read a specified amount of data, stop when $size is reached, eof or newline.
This is guaranteed to return, and has the added benefit of gettingeverything in one fread() chunk; if you know the size of the datayou're getting beforehand, this is definitely the way to go.if the param $connection is given, this method is used static.
|
| Parameter |
|
| int |
$size |
|
|
the number of bytes to read from the socket. |
|
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
string $size bytes of data from the socket |
| See Also |
read(), readLine(), readAll() |
|
read |
|
public string read( int $size, string $connection )
|
| |
Read a specified amount of data, stop when $size is reached or eof. continue on a newline.
This is guaranteed to return, and has the added benefit of gettingeverything in one fread() chunk; if you know the size of the datayou're getting beforehand, this is definitely the way to go.if the param $connection is given, this method is used static.
|
| Parameter |
|
| int |
$size |
|
|
the number of bytes to read from the socket. |
|
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
string $size bytes of data from the socket |
| See Also |
gets(), readLine(), readAll() |
|
writeLine |
|
public bool writeLine( string $line, [ string $crLf ], string $connection )
|
| |
Write a line to the connection.
if the param $connection is given, this method is used static.
|
| Parameter |
|
|
|
| string |
$crLf |
= >>"\r\n"<< |
|
the carriage return/line feed to add to the line, or any other string. default is "\r\n". |
|
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
bool true on success, false on failure. |
| See Also |
write() |
|
write |
|
public bool write( string $data, string $connection )
|
| |
Write data to the connection.
if the param $connection is given, this method is used static.
|
| Parameter |
|
|
|
| string |
$connection |
|
|
Warning: documentation is missing. |
|
| Returns |
bool true on success, false on failure. |
| See Also |
writeLine() |
|
getErrorMessage |
|
public string getErrorMessage( long $errCode )
|
| |
Return a textual error message for a bs socket error code
|
| Parameter |
|
| long |
$errCode |
|
|
a bs error code (see constants) |
|
| Returns |
string error message, or false if the error code was not recognized |
|
Bs_SocketClient |
|
public void Bs_SocketClient( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|