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

Class: Net_Socket

Source Location: /Net_Socket-1.0.5/Socket.php

Class Overview

PEAR
   |
   --Net_Socket

Generalized Socket class.


Author(s):

Version:

  • 1.1

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 35]
Generalized Socket class.


[ Top ]


Class Variables

$addr =  ''

[line 59]

The IP address to connect to.

Type:   string


[ Top ]

$blocking =  true

[line 47]

Whether the socket is blocking. Defaults to true.

Type:   boolean


[ Top ]

$fp =  null

[line 41]

Socket file pointer.

Type:   resource


[ Top ]

$lineLength =  2048

[line 79]

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

Type:   integer


[ Top ]

$persistent =  false

[line 53]

Whether the socket is persistent. Defaults to false.

Type:   boolean


[ Top ]

$port =  0

[line 65]

The port number to connect to.

Type:   integer


[ Top ]

$timeout =  false

[line 72]

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

Type:   integer


[ Top ]



Method Detail

connect   [line 95]

mixed 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: true on success or error object
  • 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) How long to wait for data.
array   $options   —  See options for stream_context_create.

[ Top ]

disconnect   [line 154]

mixed disconnect( )

Disconnects from the peer, closes the socket.
  • Return: true on success or an error object otherwise
  • Access: public

[ Top ]

eof   [line 303]

bool eof( )

Tests for end-of-file on a socket descriptor.
  • Access: public

[ Top ]

gets   [line 242]

$size gets( $size)

Get a specified line of data
  • Return: bytes of data from the socket, or a PEAR_Error if not connected.
  • Access: public

Parameters:

   $size   — 

[ Top ]

getStatus   [line 227]

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 an error object otherwise
  • Access: public

[ Top ]

isBlocking   [line 170]

boolean isBlocking( )

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

[ Top ]

read   [line 261]

$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 426]

All readAll( )

Read until the socket closes. THIS FUNCTION WILL NOT EXIT if the socket is in blocking mode until the socket closes.
  • Return: data until the socket closes, or a PEAR_Error if not connected.
  • Access: public

[ Top ]

readByte   [line 315]

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 346]

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 382]

Dot readIPAddress( )

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

[ Top ]

readLine   [line 401]

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 363]

string, readString( )

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

[ Top ]

readWord   [line 330]

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 450]

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 185]

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 an error object otherwise
  • Access: public

Parameters:

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

[ Top ]

setTimeout   [line 204]

mixed setTimeout( integer $seconds, integer $microseconds)

Sets the timeout value on socket descriptor, expressed in the sum of seconds and microseconds
  • Return: true on success or an error object otherwise
  • Access: public

Parameters:

integer   $seconds   —  Seconds.
integer   $microseconds   —  Microseconds.

[ Top ]

write   [line 275]

mixed write( $data)

Write a specified amount of data.
  • Return: true on success or an error object otherwise
  • Access: public

Parameters:

   $data   — 

[ Top ]

writeLine   [line 289]

mixed writeLine( $data)

Write a line of data to the socket, followed by a trailing "\r\n".
  • Return: fputs result, or an error
  • Access: public

Parameters:

   $data   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:12:52 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.