PHP socket 连接 Socket server
2009-05-03 22:30
501 查看
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 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 |
<?
// 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);
?>
相关文章推荐
- mysql连接之ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2
- PHP配置MS SQLServer数据库连接
- Ubuntu14连接MySql报错“can't connect to local mysql server through socket '/var/run/mysqld/mysqld.sock'”
- 利用线程池实现ServerSocket的多客户端连接
- php在windows下连接Microsoft SQL Server(SQLServer)
- 使用PHP+FreeTDS在Linux下连接MS SQLServer数据库
- Socket 和ServerSocket的连接 .单一的聊天,随便输入输出
- 连接不到 Linux 上的 zookeeper 异常:Session 0x0 for server null,unexpected error, closing socket connection a
- php连接redis出现Redis server went away
- 如何putty安装php, apache, mysql(LAMP), 连接digital ocean server, 将自己的网站po上server
- Redis源码系列28:ServerSocket接收到client的连接请求处理过程
- 最简单的PHP socket echo server。
- PHP连接Microsoft SQL Server 2000/2005/2008
- 使用PHP、FreeTDS在Linux下连接MS SQLServer数据库 [linux]
- Mysql连接的过程中出现Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
- QTcpServer多个TcpSocket连接
- 关于PHP中Socket连接及读写数据超时的问题
- 连接MySql报错“can't connect to local mysql server through socket '/var/run/mysqld/mysqld.sock'”
- 连接Mysql提示Can’t connect to local MySQL server through socket的解决方法
- Linux下PHP连接MS SQLServer的办法