0

以下は、着信メッセージ (XML 文字列) をリッスンするために作成した PHP スクリプトです。

その PHP スクリプトは、ポート 13330 のローカル ホーム サーバーでホストされているので、受信リクエストをリッスンする場所ですよね? そのため、ソケットを作成し、ファイルがあるアドレスにバインドします。

次のエラーが表示されます: 警告: socket_bind(): アドレス [0] をバインドできません: 通常、各ソケット アドレス (プロトコル/ネットワーク アドレス/ポート) の使用は 1 つだけ許可されています。

なぜ私がそれを見ているのか、誰かが私に知らせてくれれば幸いです。

ありがとう

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;
}
4

1 に答える 1