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

Class: Net_Socket

Source Location: /Net_Socket-1.0.6/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 97]

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) How long to wait for data.
array   $options   —  See options for stream_context_create.

[ Top ]

disconnect   [line 157]

mixed disconnect( )

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

[ Top ]

eof   [line 335]

bool eof( )

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

[ Top ]

gets   [line 248]

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

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

boolean isBlocking( )

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

[ Top ]

read   [line 268]

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

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

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

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

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

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

string, readString( )

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

[ Top ]

readWord   [line 363]

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

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

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

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

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

Write a specified amount of data.
  • Return: true on success or an error object otherwise
  • 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 320]

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