本文整理汇总了PHP中socket_strerror函数的典型用法代码示例。如果您正苦于以下问题:PHP socket_strerror函数的具体用法?PHP socket_strerror怎么用?PHP socket_strerror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了socket_strerror函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processPacket
function processPacket($packetData)
{
$packet = new dhcpPacket();
$packet->parse($packetData);
$processor = new dhcpRequestProcessor($this, $this->packetProcessor, $this->storage, $packet);
if ($responsePacket = $processor->getResponse()) {
$responseData = $responsePacket->build();
$this->verbosity && (print "Sending response" . "\n");
$ciaddr = $packet->getClientAddress();
if ($ciaddr == '0.0.0.0') {
$this->verbosity && (print "Switching to broadcast address...\n");
$ciaddr = '255.255.255.255';
}
$this->verbosity && (print "Attempting to send response packet to " . $ciaddr . "\n");
$numBytesSent = socket_sendto($this->socket, $responseData, strlen($responseData), 0, $ciaddr, 68);
if ($numBytesSent === FALSE) {
$this->verbosity && (print "send failed for specific address, broadcast.\n");
$numBytesSent = socket_sendto($this->socket, $responseData, strlen($responseData), 0, "255.255.255.255", 68);
$numBytesSent === FALSE && $this->verbosity && printf('socket send error: %s\\n', socket_strerror(socket_last_error($this->socket)));
}
$numBytesSent && $this->verbosity && (print "Response packet sent.\n");
} else {
$this->verbosity && (print "Packet ignored\n");
}
}
示例2: queryAPI
function queryAPI($jsonQuery)
{
$service_port = 12345;
$address = "localhost";
$msg = "{\n \"array\": [\n";
echo $msg;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
die('{"type" : "error", "msg" : "connection error: ' . socket_strerror(socket_last_error()) . '"}]}');
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
die('{"type" : "error", "msg" : "connection error: ' . socket_strerror(socket_last_error($socket)) . '"}]}');
}
$in = stripslashes($jsonQuery);
socket_write($socket, $in, strlen($in));
socket_write($socket, ';', 1);
$buffer = "";
while ($out = socket_read($socket, 2048)) {
echo $out;
ob_flush();
flush();
}
#JSON Array end
$msg = "]\n }";
echo $msg;
echo PHP_EOL;
ob_flush();
flush();
socket_close($socket);
}
示例3: getsock
function getsock($port)
{
$socket = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false || $socket === null) {
$error = socket_strerror(socket_last_error());
$msg = "socket create({$port}) failed";
echo "ERR: {$msg} '{$error}'\n";
return NULL;
}
socket_set_nonblock($socket);
$res = socket_connect($socket, API_HOST, $port);
$timeout = 50;
while ($res === false && $timeout > 0) {
$err = socket_last_error($socket);
echo ".";
if ($timeout > 1 && ($err == 115 || $err == 114)) {
$timeout--;
usleep(50);
$res = socket_connect($socket, API_HOST, $port);
continue;
}
$error = socket_strerror($err);
$msg = "socket connect({$port}) failed";
echo "ERR: {$msg} '{$error}'\n";
socket_close($socket);
return NULL;
}
socket_set_block($socket);
return $socket;
}
示例4: sendUSD
function sendUSD($text, $pass_server = '000000')
{
$address = gethostbyname('127.0.0.1');
//IP Адрес вашего компьютера
$service_port = 8000;
//Порт
//$pass_server='000000'; //Пароль
$phone = preg_replace('/^\\+/', '', $phone);
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
echo "socket create failed reason: " . socket_strerror($socket) . "\n";
}
$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
echo "socket connect failed.\nReason: ({$result}) " . socket_strerror($result) . "\n";
}
$text = iconv("UTF-8", "Windows-1251", $text);
$in = base64_encode($pass_server . "#CMD#[USSD]" . $text);
//Пример отправки смс
//$in = base64_encode($pass_server."#CMD#[USSD]*102#"); //Пример запроса USSD команды
$out = '';
socket_write($socket, $in, strlen($in));
//echo "Response:\n\n";
$res = '';
while ($out = socket_read($socket, 2048)) {
$res .= $out;
}
socket_close($socket);
$res = iconv("Windows-1251", "UTF-8", $res);
if (preg_match('/USSD-RESPONSE\\[.+?\\]:(.+)/is', $res, $m)) {
$res = $m[1];
}
return $res;
}
示例5: sendsock
function sendsock($in)
{
global $config;
$service_port = $config['sockport'];
$address = $config['sockhost'];
if (!function_exists("socket_create")) {
error_log(date("y-m-d H:i:s") . " 未启用socket模块\n", 3, "error.log");
return null;
}
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
error_log(date("y-m-d H:i:s") . "socket_create() failed, reason: " . socket_strerror(socket_last_error()) . "\n", 3, "error.log");
return null;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
error_log(date("y-m-d H:i:s") . "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket)) . "\n", 3, "error.log");
return null;
}
socket_write($socket, $in, strlen($in));
$result = socket_read($socket, 8192);
$arr = unpack("C*", $result);
socket_close($socket);
return $arr;
}
示例6: coop_send
function coop_send($message)
{
if (!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [{$errorcode}] {$errormsg} \n");
}
//Connect socket to remote server
if (!socket_connect($sock, COOPSERVER, COOPPORT)) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not connect: [{$errorcode}] {$errormsg} \n");
}
//Send the message to the server
if (!socket_send($sock, $message, strlen($message), 0)) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [{$errorcode}] {$errormsg} \n");
}
$buf = 'my buffer';
if (false !== ($bytes = socket_recv($sock, $buf, 1024, 0))) {
echo "Read {$bytes} bytes of socket_recv(). close socket ...";
} else {
echo "socket_recv() error; Reason: " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_close($sock);
return $buf;
}
示例7: WakeOnLan
function WakeOnLan($addr, $mac_address, $socket_number)
{
$addr_byte = explode(':', $mac_address);
$hw_addr = '';
for ($a = 0; $a < 6; $a++) {
$hw_addr .= chr(hexdec($addr_byte[$a]));
$msg = chr(255) . chr(255) . chr(255) . chr(255) . chr(255) . chr(255);
for ($a = 1; $a <= 16; $a++) {
$msg .= $hw_addr;
// send it to the broadcast address using UDP
// SQL_BROADCAST option isn't help!!
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($s == false) {
echo "Error creating socket!\n";
echo "Error code is '" . socket_last_error($s) . "' - " . socket_strerror(socket_last_error($s));
return FALSE;
} else {
// setting a broadcast option to socket:
$opt_ret = socket_set_option($s, 1, 6, TRUE);
if ($opt_ret < 0) {
echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
return FALSE;
}
if (socket_sendto($s, $msg, strlen($msg), 0, $ip_address, $socket_number)) {
echo "Magic Packet sent successfully!";
socket_close($s);
return TRUE;
} else {
echo "Magic packet failed!";
return FALSE;
}
}
}
}
}
示例8: getSocketError
/**
* @param resource $socket
* @return string
*/
protected function getSocketError($socket = null)
{
if ($socket === null && $this->socket) {
$socket = $this->socket;
}
return socket_strerror(socket_last_error($socket));
}
示例9: server_loop
function server_loop($address, $port)
{
global $__server_listening;
// AF_UNIX AF_INET
if (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) < 0) {
events("failed to create socket: " . socket_strerror($sock), __FUNCTION__, __LINE__);
exit;
}
if (($ret = socket_bind($sock, $address, $port)) < 0) {
events("failed to bind socket: " . socket_strerror($ret), __FUNCTION__, __LINE__);
exit;
}
if (($ret = socket_listen($sock, 0)) < 0) {
events("failed to listen to socket: " . socket_strerror($ret), __FUNCTION__, __LINE__);
exit;
}
socket_set_nonblock($sock);
events(count($GLOBALS["LOCAL_DOMAINS"]) . " internals domains...", __FUNCTION__, __LINE__);
events("waiting for clients to connect", __FUNCTION__, __LINE__);
while ($__server_listening) {
$connection = @socket_accept($sock);
if ($connection === false) {
if ($GLOBALS["DebugArticaFilter"] == 1) {
events("sleep", __FUNCTION__, __LINE__);
}
usleep(2000000);
} elseif ($connection > 0) {
handle_client($sock, $connection);
} else {
events("error: " . socket_strerror($connection), __FUNCTION__, __LINE__);
die;
}
}
}
示例10: _checkClosedRequests
protected function _checkClosedRequests()
{
foreach ($this->_clients as $key => $client) {
if (in_array($client, $this->_read)) {
$buf = @socket_read($client, 1024, PHP_NORMAL_READ);
if ($buf === false) {
throw new Exception\Listener(socket_strerror(socket_last_error($client)));
}
$buf = trim($buf);
if ($buf) {
switch ($buf) {
case 'quit':
print "Close connection\n";
unset($this->_clients[$key]);
$this->_requests[$key]->finished = true;
unset($this->_requests[$key]);
socket_close($client);
break;
case 'shutdown':
throw new Exception\Listener('Shutdown detected');
}
}
}
}
return true;
}
示例11: await
private function await()
{
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($sock < 0) {
echo "Error:" . socket_strerror(socket_last_error()) . "\n";
}
$ret = socket_bind($sock, $this->ip, $this->port);
if (!$ret) {
echo "BIND FAILED:" . socket_strerror(socket_last_error()) . "\n";
exit;
}
echo "OK\n";
$ret = socket_listen($sock);
if ($ret < 0) {
echo "LISTEN FAILED:" . socket_strerror(socket_last_error()) . "\n";
}
do {
$new_sock = null;
try {
$new_sock = socket_accept($sock);
} catch (Exception $e) {
echo $e->getMessage();
echo "ACCEPT FAILED:" . socket_strerror(socket_last_error()) . "\n";
}
try {
$request_string = socket_read($new_sock, 1024);
$response = $this->output($request_string);
socket_write($new_sock, $response);
socket_close($new_sock);
} catch (Exception $e) {
echo $e->getMessage();
echo "READ FAILED:" . socket_strerror(socket_last_error()) . "\n";
}
} while (TRUE);
}
示例12: mainLoop
private function mainLoop()
{
$changed_sockets = $this->allsockets;
@socket_select($changed_sockets, $write = null, $exceptions = null, 0);
foreach ($this->apps as $app) {
$app->onTick();
}
foreach ($changed_sockets as $socket) {
if ($socket == $this->master) {
if (($rec = socket_accept($this->master)) < 0) {
$this->log("Error: Could not connect\n" . socket_strerror(socket_last_error($rec)));
continue;
} else {
$this->log("New client connecting...");
$client = new Connection($this, $rec);
$this->clients[$rec] = $client;
$this->allsockets[] = $rec;
}
} else {
$client = $this->clients[$socket];
$bytes = @socket_recv($socket, $data, 4096, 0);
if (!$bytes) {
$client->onDisconnect();
unset($this->clients[$socket]);
$index = array_search($socket, $this->allsockets);
unset($this->allsockets[$index]);
unset($client);
} else {
$client->onData($data);
}
}
}
}
示例13: sendcmd
function sendcmd($in, $address, $service_port)
{
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
return "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
return "socket_connect() failed.\nReason: ({$result}) " . socket_strerror(socket_last_error($socket)) . "\n";
}
socket_write($socket, $in, strlen($in));
$mess = "";
/*$next = "";*/
sleep(1);
/*$next = socket_read($socket, 4096);*/
while (0 != socket_recv($socket, $out, 4096, MSG_DONTWAIT)) {
if ($out != null) {
$mess .= $out;
}
}
/*$mess .= $next;*/
socket_close($socket);
return $mess;
}
示例14: create_connection
function create_connection($host, $port)
{
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!is_resource($socket)) {
echo 'Unable to create socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
} else {
echo "Socket created.\n";
}
if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
echo 'Unable to set option on socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
} else {
echo "Set options on socket.\n";
}
if (!socket_bind($socket, $host, $port)) {
echo 'Unable to bind socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
} else {
echo "Socket bound to port {$port}.\n";
}
if (!socket_listen($socket, SOMAXCONN)) {
echo 'Unable to listen on socket: ' . socket_strerror(socket_last_error());
} else {
echo "Listening on the socket.\n";
}
while (true) {
$connection = @socket_accept($socket);
if ($connection) {
echo "Client {$connection} connected!\n";
send_data($connection);
} else {
echo "Bad connection.";
}
}
}
示例15: __construct
public function __construct()
{
$this->socket = socket_create(AF_INET, SOCK_STREAM, 0);
if ($this->socket < 0) {
sendError('socket_create() failed: reason: ' . socket_strerror($this->socket));
}
}