我想问一下如何创建一个能够实时接收Android手机请求的PHP套接字?现在,我完成了这部分代码并使用telnet进行测试.但是,当Android手机尝试连接时,它无法接收或发送任何东西到服务器.
if (!defined('SOCKET_ADDRESS')) {
define('SOCKET_ADDRESS', '192.168.1.4');
}
if (!defined('SOCKET_PORT')) {
define('SOCKET_PORT', '5888');
}
if (!defined('MAX_CLIENTS')) {
define('MAX_CLIENTS', '10');
}
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socket, SOCKET_ADDRESS, SOCKET_PORT) or die('Could not bind to address ' . SOCKET_ADDRESS . ' on port ' . SOCKET_PORT . "!\n");
socket_listen($socket, MAX_CLIENTS) or die("Could not setup socket listener!\n");
// setup read socket array
$read = array();
// client array w/ default initial socket
$clients = array('0' => array('socket' => $socket)); …Run Code Online (Sandbox Code Playgroud)