2017-11-20 28 views
0

を生きていない私は、GoDaddyのドメインをホスティングしていると私はソケットモジュールを有効になっていますが、私はそれが動作しないサーバーでそれをアップロードする際に、このコードは、ローカルホストでのみ動作 に動作しない用量。PHPソケットサーバがローカルホスト上でのみ動作しますが、サーバー

コードserver.phpという

<?php 
// set some variables 
$host = '150.113.178.20'; 
$port = 5000; 

if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0))) 
{ 
    $errorcode = socket_last_error(); 
    $errormsg = socket_strerror($errorcode); 

    die("Couldn't create socket: [$errorcode] $errormsg \n"); 
} 

echo "Socket created \n"; 

// Bind the source address 
if(!socket_bind($sock, $host , $port)) 
{ 
    $errorcode = socket_last_error(); 
    $errormsg = socket_strerror($errorcode); 

    die("Could not bind socket : [$errorcode] $errormsg \n"); 
} 

echo "Socket bind OK \n"; 

if(!socket_listen ($sock , 10)) 
{ 
    $errorcode = socket_last_error(); 
    $errormsg = socket_strerror($errorcode); 

    die("Could not listen on socket : [$errorcode] $errormsg \n"); 
} 

echo "Socket listen OK \n"; 

echo "Waiting for incoming connections... \n"; 

//start loop to listen for incoming connections 
while (true) 
{ 
    //Accept incoming connection - This is a blocking call 
    $client = socket_accept($sock); 

    //display information about the client who is connected 
    if(socket_getpeername($client , $address , $port)) 
    { 
     echo "Client $address : $port is now connected to us. \n"; 
    } 

    //read data from the incoming socket 
    $input = socket_read($client, 1024000); 

    $response = "OK .. $input"; 

    // Display output back to client 
    socket_write($client, $response); 
} 

私はSSHには問題

enter image description here

をserver.phpというスクリプトを実行していないが、私はCMDから書くとき:

enter image description here

いくつかの研究の後

エラーログファイル

enter image description here

+0

エラーログを確認しましたか? –

+0

そのIPは確かですか? –

+0

ここでコードと写真を私はちょうど例を与えたが、はい私のコードIPアドレスで確かに正しいです。 –

答えて

0

私はコードが GoDaddyのは、カスタムポートを開きません正しいことがわかりました。 GoDaddy(または他のホスティングWebサイト)とは異なるセキュリティポリシーのローカルホストを使用しているため、コードが機能しません。