极乐门资源网 Design By www.ioogu.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.ioogu.com
极乐门资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com
暂无PHP实现Socket服务器的代码的评论...
更新日志
2025年01月03日
2025年01月03日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]