2013-07-10 31 views
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 &#8211; 1024 bytes 
    $input = socket_read($client, 1024); 

    // Strip all white spaces from input 
    $output = ereg_replace("[ \t\n\r]","",$input).chr(0); 
    echo $output; 
} 
+0

最有可能的事情已經在使用該端口 - netstat顯示你什麼? – symcbean

+0

@symcbean我可以將套接字端口綁定到我託管WAMP服務器的端口嗎?還是必須有所不同? – jskidd3

+1

它必須有所不同:通常只允許使用每個套接字地址(協議/網絡地址/端口)。 – symcbean

回答

相關問題