File source
<?php
include_once "Port.php";
/** Network version (for TCP transport / virtual COM port)
of Port Class
*/
class NetPort extends Port{
protected $server;
protected $port;
protected $fd = false;
function __construct($server, $port){
$this->server = $server;
$this->port = $port;
}
function open(){
$this->close();
$this->fd = fsockopen($this->server, $this->port);
if(!$this->fd){
throw new Exception("Could not open port: ".$this->server.":".$this->port);
}
stream_set_blocking($this->fd, 1);
}
function close(){
if($this->fd){
fclose($this->fd);
}
$this->fd = false;
}
function setTimeout($t){
$sec = floor($t/1000);
$usec = ($t - $sec*1000)*1000;
socket_set_timeout($this->fd,$sec,$usec);
}
}