PHP socket 连接 Socket server

socket_send

(PHP 4 >= 4.1.0, PHP 5)

socket_send -- Sends data to a connected socket

Description

int socket_send ( resource socket, string buf, int len, int flags)

 

警告

本扩展模块是实验性的。该模块的行为,包括其函数的名称以及其它任何关于此模块的文档可能会在没有通知的情况下随 PHP 以后的发布而改变。我们提醒您在使用本扩展模块的同时自担风险。

The function socket_send() sends len bytes to the socket socket from buf

The value of flags can be any ORed combination of the following:

表格 1. possible values for flags

0x1 Process OOB (out-of-band) data
0x2 Peek at incoming message
0x4 Bypass routing, use direct interface
0x8 Data completes record
0x100 Data completes transaction

 

See also socket_sendmsg() and socket_sendto().

 

 

 <?

// set some variables
$host = "10.1.0.3";
$port = 5038;

// don't timeout!
set_time_limit(0);

// create socket
$commonProtocol = getprotobyname("tcp");
$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol) or die("Could not create
socket/n");
$connection=socket_connect($socket,$host,$port);
if (!$connection)
{
 echo "Can't Connect to Asterisk Manager Port .";
}
else
{
 echo "Connect to Asterisk Manager Successfully.";
}

$Socket_logintext="Action: login/r/nUsername: cron/r/nSecret: 1234/r/nEvents: ON/r/n/r/n";
socket_send($socket,$Socket_logintext,strlen($Socket_logintext),0x4);
//socket_write($socket,$Socket_logintext,strlen($Socket_logintext));
/*
while ($buffer=socket_read($socket,1024,PHP_NORMAL_READ))
 {
 if($buffer=="NO DATA");
 {
  echo ("<p>NO DATA</p>");
  continue;
 }
 else
 {
  echo ("<p>Buffer Data: ".$buffer."</p>");
 }
}
*/
socket_close($socket);
?>

 

你可能感兴趣的:(PHP,socket,manager,buffer,interface,variables)