TeamSpeak 3 PHP Framework
Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
TeamSpeak3_Transport_UDP Class Reference

Class for connecting to a remote server through UDP. More...

+ Inheritance diagram for TeamSpeak3_Transport_UDP:

Public Member Functions

 connect ()
 Connects to a remote server. More...
 
 disconnect ()
 Disconnects from a remote server. More...
 
 read ($length=4096)
 Reads data from the stream. More...
 
 send ($data)
 Writes data to the stream. More...
 
- Public Member Functions inherited from TeamSpeak3_Transport_Abstract
 __construct (array $config)
 The TeamSpeak3_Transport_Abstract constructor. More...
 
 __destruct ()
 The TeamSpeak3_Transport_Abstract destructor. More...
 
 __sleep ()
 Commit pending data. More...
 
 __wakeup ()
 Reconnects to the remote server. More...
 
 connect ()
 Connects to a remote server. More...
 
 disconnect ()
 Disconnects from a remote server. More...
 
 getAdapter ()
 Returns the TeamSpeak3_Adapter_Abstract object using this transport. More...
 
 getAdapterType ()
 Returns the adapter type. More...
 
 getConfig ($key=null, $default=null)
 Returns the configuration variables in this adapter. More...
 
 getMetaData ()
 Returns header/meta data from stream pointer. More...
 
 getStream ()
 Returns the underlying stream resource. More...
 
 isConnected ()
 Returns TRUE if the transport is connected. More...
 
 read ($length=4096)
 Reads data from the stream. More...
 
 send ($data)
 Writes data to the stream. More...
 
 setAdapter (TeamSpeak3_Adapter_Abstract $adapter)
 Sets the TeamSpeak3_Adapter_Abstract object using this transport. More...
 

Additional Inherited Members

- Protected Member Functions inherited from TeamSpeak3_Transport_Abstract
 waitForReadyRead ($time=0)
 Blocks a stream until data is available for reading if the stream is connected in non-blocking mode. More...
 

Detailed Description

Class for connecting to a remote server through UDP.

Member Function Documentation

◆ connect()

connect ( )

Connects to a remote server.

Exceptions
TeamSpeak3_Transport_Exception
Returns
void
38  {
39  if($this->stream !== null) return;
40 
41  $host = strval($this->config["host"]);
42  $port = strval($this->config["port"]);
43 
44  $address = "udp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
45  $timeout = (int) $this->config["timeout"];
46 
47  $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout);
48 
49  if($this->stream === FALSE)
50  {
51  throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
52  }
53 
54  @stream_set_timeout($this->stream, $timeout);
55  @stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0);
56  }
Enhanced exception class for TeamSpeak3_Transport_Abstract objects.
Definition: Exception.php:29
static factory($string)
Returns a TeamSpeak3_Helper_String object for thegiven string.
Definition: String.php:60

◆ disconnect()

disconnect ( )

Disconnects from a remote server.

Returns
void
64  {
65  if($this->stream === null) return;
66 
67  $this->stream = null;
68 
69  TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "Disconnected");
70  }
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
getAdapterType()
Returns the adapter type.
Definition: Abstract.php:204

◆ read()

read (   $length = 4096)

Reads data from the stream.

Parameters
integer$length
Exceptions
TeamSpeak3_Transport_Exception
Returns
TeamSpeak3_Helper_String
80  {
81  $this->connect();
82  $this->waitForReadyRead();
83 
84  $data = @fread($this->stream, $length);
85 
86  TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data);
87 
88  if($data === FALSE)
89  {
90  throw new TeamSpeak3_Transport_Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost");
91  }
92 
93  return new TeamSpeak3_Helper_String($data);
94  }
waitForReadyRead($time=0)
Blocks a stream until data is available for reading if the stream is connected in non-blocking mode...
Definition: Abstract.php:249
Helper class for string handling.
Definition: String.php:29
connect()
Connects to a remote server.
Definition: UDP.php:37
Enhanced exception class for TeamSpeak3_Transport_Abstract objects.
Definition: Exception.php:29
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
getAdapterType()
Returns the adapter type.
Definition: Abstract.php:204

◆ send()

send (   $data)

Writes data to the stream.

Parameters
string$data
Returns
void
103  {
104  $this->connect();
105 
106  @stream_socket_sendto($this->stream, $data);
107 
108  TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataSend", $data);
109  }
connect()
Connects to a remote server.
Definition: UDP.php:37
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
getAdapterType()
Returns the adapter type.
Definition: Abstract.php:204

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