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

Class: Net_Socket

Source Location: /Net_Socket-1.0.3/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 94]

mixed connect( $addr $addr, [$port $port = 0], [$persistent $persistent = null], [$timeout $timeout = null], [$options $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:

$addr   $addr   —  string IP address or host name
$port   $port   —  int TCP port number
$persistent   $persistent   —  bool (optional) whether the connection is persistent (kept open between requests by the web server)
$timeout   $timeout   —  int (optional) how long to wait for data
$options   $options   —  array see options for stream_context_create

[ Top ]

disconnect   [line 150]

mixed disconnect( )

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

[ Top ]

eof   [line 299]

bool eof( )

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

[ Top ]

gets   [line 238]

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

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

bool isBlocking( )

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

[ Top ]

read   [line 257]

$size read( $size $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:

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

[ Top ]

readAll   [line 422]

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

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

1 readInt( )

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

[ Top ]

readIPAddress   [line 378]

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

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

string, readString( )

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

[ Top ]

readWord   [line 326]

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

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

mixed setBlocking( $mode $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:

$mode   $mode   —  bool true for blocking sockets, false for nonblocking

[ Top ]

setTimeout   [line 200]

mixed setTimeout( $seconds $seconds, $microseconds $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:

$seconds   $seconds   —  int seconds
$microseconds   $microseconds   —  int microseconds

[ Top ]

write   [line 271]

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

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 13:59:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.