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. Dismiss Notice

Database connectivity - WebPlayer VS WebGL

Discussion in 'General Discussion' started by rxmarccall, Oct 16, 2014.

  1. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I had a question concerning WebGL in Unity 5. I have a client that needs a browser based application that will need to communicate with a database one way or another. I found a thread in Unity Answers of someone saying that the current Web Player can communicate using the WWW class, but then on the WWW class documentation it says "Note: The security sandbox present in web-player builds prevents you from accessing content not hosted the server where the webplayer is hosted."

    Which of these is true? In regards to WebGL in Unity 5, will this security sandbox be removed so that we could have a way to communicate with a database?
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,065
    Best thing to do is write a server program that accesses the database and have your game communicate with that. I wouldn't have a game access the database directly as it won't be as secure.
     
    angrypenguin likes this.
  3. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    2,980
    You should not connect directly to a DB server from a game. You want to connect to a web service and then have the web service interact with the DB.
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Sure, but this isn't very useful without explaining why.

    Anyone can connect to your server and send any data to it. If your game connects directly then there's nothing you can do about this. If you wrap it in a web service you've got a layer in which you can sanity check the data, sanitize it, and generally provide some level of security. It'll never be perfect, but it can be good enough.
     
    Graham-Dunnett likes this.
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,952
    Both are true. You can access content via WWW, as long as it is on the same server. The security sandbox is there for a reason, there is no need for it to be removed. You can access your content/services with no problem.
     
  6. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Thanks guys, I wasn't fully understanding the sentance about both the web application and Database needing to being on the same server, that makes sense now. And yea I for sure intend to communicate via web services. Thanks for the quick responses.
     
  7. Bladesfist

    Bladesfist

    Joined:
    Jan 3, 2012
    Posts:
    107
    You can talk to other hosts as well as long as they have a crossdomain file.
     
    Graham-Dunnett likes this.