Código PHP:
abstract class Socket_Layer {
protected $socket = null;
protected $socket_domain = AF_INET;
protected $socket_type = SOCK_STREAM;
protected $socket_port = 8550;
protected $socket_address = '127.0.0.1';
protected $string_date = 'Y-m-d H:i:s';
protected $max_read_bytes = 2048;
protected $limit_time = 0;
//sets undefined execution time for the script
public function __construct() {
set_time_limit($this->limit_time);
return true;
}
final public function open_socket() {
$socket = @socket_create($this->socket_domain,$this->socket_type,0);
if ( $socket !== false ) {
$this->socket = $socket;
return true;
} else {
$errno = socket_last_error();
$erstr = socket_strerror($errno);
$this->console_message("Unable to create socket: $erstr");
die();
}
}
}
Código PHP:
include_once('Socket_Layer.php');
abstract class Socket_Server extends Socket_Layer {
protected $socket_clients = Array();
protected $read_sockets = Array();
public function __construct() {
parent::__construct();
return true;
}
abstract protected function send_response($socket,$response,$response_args = Array()); //every server has to send response
final public function start_server() {
$this->listen();
$this->console_message("Server started.");
$this->console_message("Socket IP Address: {$this->socket_address}.");
$this->console_message("Socket Port:{$this->socket_port}");
while ( true ) {
$this->fill_read_sockets();
$this->console_message("Waiting...");
$ready = socket_select($this->read_sockets,$write = null,$except = null,null);
$this->add_client();
$this->read_input();
$this->handle_data();
}
}
final protected function listen() {
if ( !@socket_bind($this->socket,$this->socket_address,$this->socket_port) ) {
$errno = socket_last_error();
$erstr = socket_strerror($errno);
$this->console_message("Unable to bind socket to {$this->socket_address}:{$this->socket_port}: $erstr.");
die();
} elseif ( !@socket_listen($this->socket) ) {
$errno = socket_last_error();
$erstr = socket_strerror($errno);
$this->console_message("Unable to listen socket.");
die();
} else {
return true;
}
}
Código PHP:
include_once('Socket_Server.php');
include_once('Config_Master.php');
include_once('configuration_protocol.php');
final class Configuration_Server extends Socket_Server
implements configuration_protocol {
private $config_master = null;
public function __construct() {
parent::__construct();
$this->config_master = new Config_Master();
return true;
}
public function start() {
parent::start_server();
return true;
}
Código PHP:
#!/usr/bin/php -q
include_once('asterisk/Configuration_Server.php');
$server = new Configuration_Server();
$server->open_socket();
$server->start();
die("Quitting PHP Socket_Server\n");
Código:
Ideas de por que este error cuando cambio el tipo de socket? para mi es casi necesario AF_UNIX por que las comunicaciones serań unicamente internas. No tiene objeto usar AF_INET.>> Unable to bind socket to 127.0.0.1:8550: Address already in use.
gracias.