Net_Socket
[ class tree: Net_Socket ] [ index: Net_Socket ] [ all elements ]

Class: Net_Socket

Source Location: /Net_Socket-1.0.12/Net/Socket.php

Class Overview

PEAR
   |
   --Net_Socket

Generalized Socket class.


Author(s):

Copyright:

  • 1997-2003 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 47]
Generalized Socket class.


[ Top ]


Class Variables

$addr =  ''

[line 71]

The IP address to connect to.

Type:   string


[ Top ]

$blocking =  true

[line 59]

Whether the socket is blocking. Defaults to true.

Type:   boolean


[ Top ]

$fp =  null

[line 53]

Socket file pointer.

Type:   resource


[ Top ]

$lineLength =  2048

[line 91]

Number of bytes to read at a time in readLine() and readAll(). Defaults to 2048.

Type:   integer


[ Top ]

$newline =  "\r\n"

[line 97]

The string to use as a newline terminator. Usually "\r\n" or "\n".

Type:   string


[ Top ]

$persistent =  false

[line 65]

Whether the socket is persistent. Defaults to false.

Type:   boolean


[ Top ]

$port =  0

[line 77]

The port number to connect to.

Type:   integer


[ Top ]

$timeout =  null

[line 84]

Number of seconds to wait on socket operations before assuming there's no more data. Defaults to no timeout.

Type:   integer|float


[ Top ]



Method Detail

connect   [line 115]

boolean connect( string $addr, [integer $port = 0], [boolean $persistent = null], [integer $timeout = null], [array $options = null])

Connect to the specified port. If called when the socket is already connected, it disconnects and connects again.
  • Return: | PEAR_Error True on success or a PEAR_Error on failure.
  • Access: public

Parameters:

string   $addr     IP address or host name.
integer   $port     TCP port number.
boolean   $persistent     (optional) Whether the connection is persistent (kept open between requests by the web server).
integer   $timeout     (optional) Connection socket timeout.
array   $options     See options for stream_context_create.

[ Top ]

disconnect   [line 190]

mixed disconnect( )

Disconnects from the peer, closes the socket.
  • Return: true on success or a PEAR_Error instance otherwise
  • Access: public

[ Top ]

enableCrypto   [line 675]

false enableCrypto( bool $enabled, integer $type)

Turns encryption on/off on a connected socket.

Parameters:

bool   $enabled     Set this parameter to true to enable encryption and false to disable encryption.
integer   $type     Type of encryption. See stream_socket_enable_crypto() for values.

[ Top ]

eof   [line 464]

bool eof( )

Tests for end-of-file on a socket descriptor.

Also returns true if the socket is disconnected.

  • Access: public

[ Top ]

gets   [line 336]

mixed gets( [int $size = null])

Get a specified line of data
  • Return: bytes of data from the socket, or a PEAR_Error if not connected. If an error occurs, FALSE is returned.
  • Access: public

Parameters:

int   $size     Reading ends when size - 1 bytes have been read, or a newline or an EOF (whichever comes first). If no size is specified, it will keep reading from the stream until it reaches the end of the line.

[ Top ]

getStatus   [line 315]

mixed getStatus( )

Returns information about an existing socket resource.

Currently returns four entries in the result array:

<p> timed_out (bool) - The socket timed out waiting for data
blocked (bool) - The socket was blocked
eof (bool) - Indicates EOF event
unread_bytes (int) - Number of bytes left in the socket buffer
</p>

  • Return: Array containing information about existing socket resource or a PEAR_Error instance otherwise
  • Access: public

[ Top ]

isBlocking   [line 219]

boolean isBlocking( )

Find out if the socket is in blocking mode.
  • Return: The current blocking mode.
  • Access: public

[ Top ]

read   [line 361]

$size read( integer $size)

Read a specified amount of data. This is guaranteed to return, and has the added benefit of getting everything in one fread() chunk; if you know the size of the data you're getting beforehand, this is definitely the way to go.
  • Return: bytes of data from the socket, or a PEAR_Error if not connected.
  • Access: public

Parameters:

integer   $size     The number of bytes to read from the socket.

[ Top ]

readAll   [line 599]

string readAll( )

Read until the socket closes, or until there is no more data in

the inner PHP buffer. If the inner buffer is empty, in blocking mode we wait for at least 1 byte of data. Therefore, in blocking mode, if there is no data at all to be read, this function will never exit (unless the socket is closed on the remote end).

  • Return: All data until the socket closes, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readByte   [line 476]

1 readByte( )

Reads a byte of data
  • Return: byte of data from the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readInt   [line 509]

integer readInt( )

Reads an int of data
  • Return: 1 int of data from the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readIPAddress   [line 547]

Dot readIPAddress( )

Reads an IP Address and returns it in a dot formatted string
  • Return: formatted string, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readLine   [line 567]

All readLine( )

Read until either the end of the socket or a newline, whichever comes first. Strips the trailing newline from the returned data.
  • Return: available data up to a newline, without that newline, or until the end of the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readString   [line 527]

string, readString( )

Reads a zero-terminated string of data
  • Return: or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readWord   [line 492]

1 readWord( )

Reads a word of data
  • Return: word of data from the socket, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

select   [line 624]

False select( integer $state, integer $tv_sec, [integer $tv_usec = 0])

Runs the equivalent of the select() system call on the socket with a timeout specified by tv_sec and tv_usec.
  • Return: if select fails, integer describing which of read/write/error are ready, or PEAR_Error if not connected.
  • Access: public

Parameters:

integer   $state     Which of read/write/error to check for.
integer   $tv_sec     Number of seconds for timeout.
integer   $tv_usec     Number of microseconds for timeout.

[ Top ]

setBlocking   [line 235]

mixed setBlocking( boolean $mode)

Sets whether the socket connection should be blocking or not. A read call to a non-blocking socket will return immediately if there is no data available, whereas it will block until there is data for blocking sockets.
  • Return: true on success or a PEAR_Error instance otherwise
  • Access: public

Parameters:

boolean   $mode     True for blocking sockets, false for nonblocking.

[ Top ]

setNewline   [line 207]

boolean setNewline( string $newline)

Set the newline character/sequence to use.
  • Return: True

Parameters:

string   $newline     Newline character(s)

[ Top ]

setTimeout   [line 257]

mixed setTimeout( [integer $seconds = null], [integer $microseconds = null])

Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds
  • Return: True on success or false on failure or a PEAR_Error instance when not connected
  • Access: public

Parameters:

integer   $seconds     Seconds.
integer   $microseconds     Microseconds, optional.

[ Top ]

setWriteBuffer   [line 287]

mixed setWriteBuffer( integer $size)

Sets the file buffering size on the stream.

See php's stream_set_write_buffer for more information.

  • Return: on success or an PEAR_Error object otherwise
  • Access: public

Parameters:

integer   $size     Write buffer size.

[ Top ]

write   [line 384]

mixed write( string $data, [integer $blocksize = null])

Write a specified amount of data.
  • Return: If the socket is not connected, returns an instance of PEAR_Error. If the write succeeds, returns the number of bytes written. If the write fails, returns false. If the socket times out, returns an instance of PEAR_Error.
  • Access: public

Parameters:

string   $data     Data to write.
integer   $blocksize     Amount of data to write at once. NULL means all at once.

[ Top ]

writeLine   [line 447]

mixed writeLine( string $data)

Write a line of data to the socket, followed by a trailing newline.
  • Return: result, or PEAR_Error when not connected
  • Access: public

Parameters:

string   $data     Data to write

[ Top ]


Documentation generated on Thu, 16 May 2013 18:00:02 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.