Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

I need to send data to a server, no control on the server side, how?

Discussion in 'Flash' started by Suminsky, May 31, 2012.

  1. Suminsky

    Suminsky

    Joined:
    Aug 11, 2011
    Posts:
    50
    Hi
    After the game ends or player quits, we need to send all player data to this server..This server isnt our, is our client server, and we dont have any control over it...

    So, my experience with unity and networking is zero (I worked with c++ and TCP/IP already thou..)..I just know about the WWW class, but dont have any practice.
    The data consists into player total score, score per level, name and e-mail, stuff like that..

    Whats the most practical way for doing that? Is it as simple as calling a www method? As complicated as having to create a external javascript...? Im clueless, any tips are much appreciated!
     
  2. Suminsky

    Suminsky

    Joined:
    Aug 11, 2011
    Posts:
    50
    So..I did a test case, things seems to be in the right path but, how the hell can we test it? -_-
    Heres what I did:
    Code (csharp):
    1. // Use this for initialization
    2.     void Start () {
    3.         SendDataToServer(szURL);
    4.     }
    5.  
    6.     void SendDataToServer(string szUrl_p)
    7.     {
    8.         //prepare info to send:--------------------------------------------------------------
    9.         WWWForm toSend = new WWWForm();
    10.  
    11.         toSend.AddField("nome",             name);
    12.         toSend.AddField("email",            eMail);
    13.         toSend.AddField("score_total",    scorePlayer);
    14.         toSend.AddField("enemyscore_total",       scoreEnemy);
    15.  
    16.         //-------------------------------------------------------------------------------------------------
    17.  
    18.         //send:
    19.         WWW www = new WWW(szUrl_p, toSend);
    20.  
    21.         StartCoroutine(WaitAnswerFromServer(www));
    22.     }
    23.  
    24.  
    25.     IEnumerator WaitAnswerFromServer(WWW www_p)
    26.     {
    27.         yield return www_p;
    28.  
    29.         if (www_p.error != null)
    30.         {
    31.             szError = www_p.error;
    32.             Debug.Log(www_p.error);
    33.             internalState= state.ShowDlgBoxFail;
    34.         }
    35.         else
    36.         {
    37.             internalState= state.ShowDlgBoxSuccess;
    38.         }
    39.     }
     
    Last edited: May 31, 2012