Dotclear 2.25
Loading...
Searching...
No Matches
netSocket Class Reference

Network base. More...

Inheritance diagram for netSocket:
netHttp HttpClient akismet dcStoreReader feedReader htmlValidator xmlrpcClient pingsAPI xmlrpcClientMulticall

Public Member Functions

 __construct (string $host, int $port, int $timeout=10)
 
 __destruct ()
 
 host (?string $host=null)
 
 port (?int $port=null)
 
 timeout (?int $timeout=null)
 
 setBlocking (bool $block)
 
 open ()
 
 close ()
 
 write ($data)
 
 flush ()
 
 isOpen ()
 

Protected Member Functions

 iterator ()
 

Protected Attributes

 $_host
 
 $_port
 
 $_transport = ''
 
 $_timeout
 
 $_handle
 

Detailed Description

Network base.

This class handles network socket through an iterator.

Constructor & Destructor Documentation

◆ __construct()

__construct ( string  $host,
int  $port,
int  $timeout = 10 
)

Class constructor

Parameters
string$hostServer host
int$portServer port
int$timeoutConnection timeout

◆ __destruct()

__destruct ( )

Object destructor

Calls close() method

References close().

Member Function Documentation

◆ host()

host ( ?string  $host = null)

Get / Set host

If $host is set, set $_host and returns true. Otherwise, returns $_host value.

Parameters
string$hostServer host
Returns
string|true

References $_host.

Referenced by htmlValidator\__construct(), akismet\callFunc(), netHttp\doRequest(), netHttp\getRequestURL(), netHttp\setHost(), and akismet\verify().

◆ port()

port ( ?int  $port = null)

Get / Set port

If $port is set, set $_port and returns true. Otherwise, returns $_port value.

Parameters
int$portServer port
Returns
int|true

References $_port.

Referenced by netHttp\doRequest(), netHttp\getRequestURL(), and netHttp\setHost().

◆ timeout()

timeout ( ?int  $timeout = null)

Get / Set timeout

If $timeout is set, set $_timeout and returns true. Otherwise, returns $_timeout value.

Parameters
int$timeoutConnection timeout
Returns
int|true

References $_timeout.

Referenced by htmlValidator\__construct(), and netHttp\setTimeout().

◆ setBlocking()

setBlocking ( bool  $block)

Set blocking

Sets blocking or non-blocking mode on the socket.

Parameters
bool$block
Returns
boolean

References isOpen().

◆ open()

open ( )

Open connection.

Opens socket connection and Returns an object of type netSocketIterator which can be iterate with a simple foreach loop.

Returns
netSocketIterator|bool

References iterator().

Referenced by netHttp\doRequest().

◆ close()

close ( )

Closes socket connection

References isOpen().

Referenced by __destruct(), and netHttp\doRequest().

◆ write()

write (   $data)

Send data

Sends data to current socket and returns an object of type netSocketIterator which can be iterate with a simple foreach loop.

$data can be a string or an array of lines.

Example:

<?php $s = new netSocket('www.google.com',80,2); $s->open(); $data = [ 'GET / HTTP/1.0' ]; foreach($s->write($data) as $v) { echo $v."\n"; } $s->close(); ?>

Parameters
string | array$dataData to send
Returns
netSocketIterator|false

References isOpen(), and iterator().

Referenced by netHttp\doRequest().

◆ flush()

flush ( )

Flush buffer

Flushes socket write buffer.

References isOpen().

◆ iterator()

iterator ( )
protected

Iterator

Returns
netSocketIterator|false

References isOpen().

Referenced by open(), and write().

◆ isOpen()

isOpen ( )

Is open

Returns true if socket connection is open.

Returns
bool

Referenced by close(), flush(), iterator(), setBlocking(), and write().

Field Documentation

◆ $_host

$_host
protected

Referenced by host().

◆ $_port

$_port
protected

Referenced by port().

◆ $_transport

$_transport = ''
protected

◆ $_timeout

$_timeout
protected

Referenced by timeout().

◆ $_handle

$_handle
protected

The documentation for this class was generated from the following file: