Php Listener / Client Lopped正在收听服务器?

时间:2015-09-05 21:47:02

标签: php asp.net sockets tcp

嘿是否有可能在Php中收听TCP服务器? 就像Tcp Server将Hello发送给Php然后发送它的Echo Hello World?

我已经尝试过witch socket_listen();在一个循环中

但这确实会使Endless加载页面再次创建服务器?

那么有办法吗?如果有,怎么样?或者也许使用asp.net?

感谢您的每一个答案

这里我的代码我已经尝试了

function listen(){
// Set the ip and port we will listen on
$address = '127.0.0.1';
$port = 8001;
// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
// Bind the socket to an address/port
$bind = socket_bind($sock, $address, $port);
// Start listening for connections
socket_listen($sock);
/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);
// Read the input from the client – 1024 bytes
$input = socket_read($client, 2024);
// Strip all white spaces from input
echo $input;
// Close the master sockets
$close = socket_close($sock);
var_dump($close);
listen();
}
set_time_limit (0);
listen();

0 个答案:

没有答案