C++ packets into a MySQL database question.

Discussion in 'OT Technology' started by Swerve, Nov 21, 2008.

  1. Swerve

    Swerve OT Supporter

    Joined:
    Feb 20, 2005
    Messages:
    3,175
    Likes Received:
    3
    A few of us are doing a project and I'm after some advice.

    Were providing C++ coded games for people to download and run on their own machine. The games once played are to send the score to our server.

    Using Winsock, the game sends the score in the following format:

    gameID.playerID.score

    Were opting to run a UDP listening service on a LAMP server.

    These 3 values are of variable lengths, separated by periods, in the form of a string.

    What I'm after is some advice on how to place the incoming data into the MySQL database.

    Any help is much appreciated!

    Thanks.
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    Why not write a simple web service instead of going through all the trouble of creating a UDP service? php/ruby/perl/etc were meant to handle such requests and can hookup to a mysql database a lot easier than writing your own native code.
     
  3. Swerve

    Swerve OT Supporter

    Joined:
    Feb 20, 2005
    Messages:
    3,175
    Likes Received:
    3
    Thanks SLED, appreciated.

    Where we are is that, last year we created some games in C++ for our course, and now we want them to send scores to our server for our new project. Only knowing C++ and SQL, we decided to use these languages to achieve our aims.

    Are you saying we could still send the packets (using Winsock), and then use a PHP script to recieve and place them into the database, this would be great if so. I'm aware that trying to use C++ with MySQL is not the norm, hence my question.

    ie:

    C++/Winsock via UDP or TCP ==> WWW ==> PHP/Server ==> MySQL


    Is this what you'd recommend?

    Certainly appears the easier option.

    Many thanks for the advice.
     
  4. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    there are millions of online resources for php and mysql connectivity so picking it up and writing a simple script to capture some data and putting it into a database is pretty trivial. I wouldn't even bother with SOAP or anything. Just have your winsock client call, for example: http://myserver.com/scoreTracker.php?Player=JOHNDOE&Score=555

    Have the php pick up those query string parameters and throw it in your mysql database.

    The benefits of using mature technology made for this kind of stuff go on and on.
     
  5. Swerve

    Swerve OT Supporter

    Joined:
    Feb 20, 2005
    Messages:
    3,175
    Likes Received:
    3
    Your a legend SLED, you've convinced me this is the way to go.

    I'm going to speak to the people I'm working with and create a PHP script for this. Much more simple and practical. I have some basic PHP skills, so hopefully it won't cause any problems.

    Again, thanks.
     
  6. telc

    telc OT Supporter

    Joined:
    Aug 29, 2003
    Messages:
    18,580
    Likes Received:
    0
    Its simple, I did it back in 2000, wrote a console app in linux that connected to the halflife WON servers using UDP and downloaded the information for every server online and all the players playing and put it into mysql.

    Include the mysql headers init the connection and call mysql_query() to insert.

    I would just do what SLED suggests, its overkill so use .NET and web services.
     
    Last edited: Nov 21, 2008
  7. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    SLED is right. What you want is a very, very simple web service. C++ is the wrong tool. Its a simple PHP app.
     
  8. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    I would suggest you don't even make it a web page, so that you don't have to worry about changing your C++ application at all.

    You can easily write a PHP script to be your UDP listen server using the socket functions: http://php.net/sockets

    Then from there, refer to the MySQL functions to write the results to MySQL.
     
  9. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Using UDP and raw sockets would be dumb. What is the benefit? HTTP is ideal for this, and PHP is the right tool for the job. Just POST the score in an http request in C++ using libcurl or something, and store it to the DB with PHP. It doesn't need an actual web page. It just needs to listen for requests.
     
  10. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    The benefit is that they don't need to alter their C++ program at all, and doesn't require anymore effort with regards to the PHP script.
     
  11. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    But UDP won't be as reliable as HTTP/TCP, and reading a POST is even easier than reading raw UDP in PHP?

    Why not use pre-built components at a higher level? Clearly he wants to re-display the scores, so a very simple PHP web app seems ideal.
     
  12. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    scalability: not found
    reliability: not found
     
  13. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Agreed.

    Also with a web service they can have better security layer.

    Do they need it? Dunno. They said they just wanted a UDP listener service so I told them how they could stick with that if they wanted to.
     

Share This Page