2017-12-03 305 views
1

我想從我的MySQL服務器獲取數據到我的Unity項目。我試圖讓像這樣的數據:如何將我的統一項目連接到EC2實例上的mysql服務器

public string awsurl = "ec2-174-129-82-141.compute-1.amazonaws.com/connect_to_server.php"; 
IEnumerator GetScores() 
{ 
     print("get scores start"); 
     WWW aws_get = new WWW(awsurl); 
     yield return aws_get; 
     print("getscore here"); 
     if (aws_get.error != null) 
     { 
      print("There was an error getting aws: " + aws_get.error); 
     } 
     else 
     { 
      print(aws_get.text); // this is a GUIText that will display the scores in game. 
     } 
} 

我有一個PHP腳本我的服務器來處理,因爲我使用的的MySqlConnection庫我合一項目有麻煩的互動上。 這裏是我的PHP腳本:

$address = "localhost" 
$dbusername = "root"; 
$dbpassword = "root"; 
$db_name = "watshoes"; 
$db_conn = new mysqli($address, $dbusername, $dbpassword, $db_name); 
    if(isset($_POST['username'])) $username = $_POST['username']; 
    if(isset($_POST['user_id'])) $user_id = $_POST['user_id']; 
    if(isset($password)) $password =$_POST['password']; 

    $stmt = $db_conn->prepare("SELECT image FROM ImageText"); 
    // "s" means the database expects a string 
    $stmt->bind_param("s", $user_id); 
    if($stmt->execute()) 
    { 
     /* bind result variables */ 
     $stmt->bind_result($image); 
     /* fetch value */ 
     $stmt->fetch(); 
     echo $image; 
    } 
    else 
    { 
     echo "query failed"; 
    } 
    $stmt->close(); 
    $db_conn->close(); 

但每次我運行代碼時我得到這個錯誤:There was an error getting aws: Failed to connect to ec2-174-129-82-141.compute-1.amazonaws.com port 80: Timed out

感謝您看代碼,並請讓我知道如果有什麼我可以做幫助。

回答

0

你必須添加規則打開端口80使用安全組(入標籤)

How should look your rule

默認情況下,端口80是AWS EC2實例關閉。

而URL是錯誤在Unity 添加http://你的服務器的URL 在編輯器將工作不正常的http://,但它會在Android的失敗。

相關問題