无为清净楼资源网 Design By www.qnjia.com
<?php
ob_implicit_flush();
set_time_limit(0);
$address = "192.40.7.93";//换成你自己的地址
$port = 10000;
if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false)
echo "错误(socket_create):".socket_strerror(socket_last_error())."<br />";
if(socket_bind($socket,$address,$port) == false)
echo "错误(socket_bind):".socket_strerror(socket_last_error())."<br />";
if(socket_listen($socket) == false)
echo "错误(socket_listen):".socket_strerror(socket_last_error())."<br />";
/*
After the socket socket has been created using socket_create() and bound to a name with socket_bind(),
it may be told to listen for incoming connections on socket.
*/
while(true){
if(($msgSocket = socket_accept($socket)) == false){
echo "错误(socket_accept):".socket_strerror(socket_last_error())."<br />";
break;
}
/*
this function will accept incoming connections on that socket.
Once a successful connection is made, a new socket resource is returned, which may be used for communication.
If there are multiple connections queued on the socket, the first will be used.
If there are no pending connections, socket_accept() will block until a connection becomes present.
If socket has been made non-blocking using socket_set_blocking() or socket_set_nonblock(), FALSE will be returned.
*/
$msg = "Welcome!<br />";
//socket_write($msg,$msg,strlen($msg));
$command = "";
while(true){
if(($buf = socket_read($msgSocket,2048,PHP_BINARY_READ)) == false){
echo "错误(socket_read):".socket_strerror(socket_last_error())."<br />";
break 2;
}
/*
The function socket_read() reads from the socket resource socket created by the socket_create() or socket_accept() functions.
The maximum number of bytes read is specified by the length parameter.
Otherwise you can use \r, \n, or \0 to end reading (depending on the type parameter, see below).
*/
/*
if(!$buf = trim($buf))
continue; // ????
if($buf == "quit")
break;
if($buf == "shutdown"){
socket_close($msgSocket);
break 2;
}
$tallBack = "You say:$buf\n";
socket_write($msgSocket,$tallBack,strlen($tallBack));
*/
if(ord($buf) != 13)
$command .= $buf;
else{
$command1 = "You Say:$command\r\n";
socket_write($msgSocket,$command1,strlen($command1));
echo "User typed:".$command."<br />";
$command = "";
}
}
socket_close($msgSocket);
}
socket_close($socket);
?>
然后打开CMD,输入:telnet 192.40.7.93 10000,自己体验去吧!
510){this.resized=true;this.style.width=510;}">
注,要把:php_sockets.dll 打开
ob_implicit_flush();
set_time_limit(0);
$address = "192.40.7.93";//换成你自己的地址
$port = 10000;
if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false)
echo "错误(socket_create):".socket_strerror(socket_last_error())."<br />";
if(socket_bind($socket,$address,$port) == false)
echo "错误(socket_bind):".socket_strerror(socket_last_error())."<br />";
if(socket_listen($socket) == false)
echo "错误(socket_listen):".socket_strerror(socket_last_error())."<br />";
/*
After the socket socket has been created using socket_create() and bound to a name with socket_bind(),
it may be told to listen for incoming connections on socket.
*/
while(true){
if(($msgSocket = socket_accept($socket)) == false){
echo "错误(socket_accept):".socket_strerror(socket_last_error())."<br />";
break;
}
/*
this function will accept incoming connections on that socket.
Once a successful connection is made, a new socket resource is returned, which may be used for communication.
If there are multiple connections queued on the socket, the first will be used.
If there are no pending connections, socket_accept() will block until a connection becomes present.
If socket has been made non-blocking using socket_set_blocking() or socket_set_nonblock(), FALSE will be returned.
*/
$msg = "Welcome!<br />";
//socket_write($msg,$msg,strlen($msg));
$command = "";
while(true){
if(($buf = socket_read($msgSocket,2048,PHP_BINARY_READ)) == false){
echo "错误(socket_read):".socket_strerror(socket_last_error())."<br />";
break 2;
}
/*
The function socket_read() reads from the socket resource socket created by the socket_create() or socket_accept() functions.
The maximum number of bytes read is specified by the length parameter.
Otherwise you can use \r, \n, or \0 to end reading (depending on the type parameter, see below).
*/
/*
if(!$buf = trim($buf))
continue; // ????
if($buf == "quit")
break;
if($buf == "shutdown"){
socket_close($msgSocket);
break 2;
}
$tallBack = "You say:$buf\n";
socket_write($msgSocket,$tallBack,strlen($tallBack));
*/
if(ord($buf) != 13)
$command .= $buf;
else{
$command1 = "You Say:$command\r\n";
socket_write($msgSocket,$command1,strlen($command1));
echo "User typed:".$command."<br />";
$command = "";
}
}
socket_close($msgSocket);
}
socket_close($socket);
?>
然后打开CMD,输入:telnet 192.40.7.93 10000,自己体验去吧!
510){this.resized=true;this.style.width=510;}">
注,要把:php_sockets.dll 打开
标签:
PHP,Socket,服务器
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月15日
2024年11月15日
- 邓丽君.1983-淡淡幽情(2022环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 试音天碟《专业测试第一天碟》经典天碟精选[WAV分轨][1G]
- 试音典范 《情惹发烧情HQCD》人声发烧极品 [WAV+CUE][1G]
- 世界顶级汽车音响试音王《幸福在路上》[低速原抓WAV+CUE][1.1G]
- 老头杯第二届什么时候开始 英雄联盟第二届老头杯开赛时间介绍
- 老头杯第二届什么时候结束 英雄联盟第二届老头杯结束时间介绍
- 老头杯第二届规则是什么 英雄联盟老头杯第二届规则介绍
- 王崴-爵士听堂.蓝色波萨(HQCD)[WAV+CUE]
- 群星《欧美动听情歌·柔情第5季》2CD【DTS-WAV分轨】
- [极品珍藏]德意志进行曲集卡拉扬SACD[WAV+CUE]
- 前暴雪制作人呼吁反击DEI 玩家:夺回文化!
- 腾讯证实子公司Sharkmob大规模裁员:整个市场很低迷
- 荣耀加冕 问鼎冠军 中国代表队获第四届东亚电竞锦标赛团体总冠军
- 污甩乐队.2024-Let.the.dirt.left【摩登天空】【FLAC分轨】
- 杜德伟.1994-ALL.FOR.YOU(英)【滚石】【WAV+CUE】