0
下面是我创建的用于侦听传入消息(XML字符串)的PHP脚本。PHP socket_bind错误(只有一个套接字地址用法)
该PHP脚本托管在我的本地家庭服务器上的端口13330,所以这就是我要监听传入的请求,对不对?所以我创建套接字并将其绑定到文件所在的地址。
我收到此错误:警告:socket_bind():无法绑定地址[0]:通常只允许使用每个套接字地址(协议/网络地址/端口)。
如果有人能告诉我为什么我可能会看到这一点,我将不胜感激。
感谢
createSocketServer();
function createSocketServer() {
// Set time limit to indefinite execution
set_time_limit (0);
// Set the ip and port we will listen on
$address = '127.0.0.1';
$port = 13330;
// Create a TCP Stream socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
echo '<p>Socket created</p>';
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address');
echo '<p>Socket binded</p>';
// Start listening for connections
socket_listen($sock);
echo '<p>Socket listening</p>';
/* 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, 1024);
// Strip all white spaces from input
$output = ereg_replace("[ \t\n\r]","",$input).chr(0);
echo $output;
}
最有可能的事情已经在使用该端口 - netstat显示你什么? – symcbean
@symcbean我可以将套接字端口绑定到我托管WAMP服务器的端口吗?还是必须有所不同? – jskidd3
它必须有所不同:通常只允许使用每个套接字地址(协议/网络地址/端口)。 – symcbean