Search Unity

Unitywebrequest(Http) and TCP connection for Realtime Games?

Discussion in 'Multiplayer' started by Crazy34, Sep 3, 2019.

  1. Crazy34

    Crazy34

    Joined:
    Jul 14, 2019
    Posts:
    69
    Hello.

    I've been developing games for about 6 years. I've made turn-based online games for the last 2 years. I have a real-time online space game made with Unitywebrequest http requests. We're developing a computer game right now. But I felt I was lacking in server-side programming. I've always used PHP-MySQL by communicating with server requests with http requests. But I've read that for a game where thousands of real-time players can be online, this connection may remain weak and put unnecessary burdens. But I don't know much about TCP socket connections. Since I'm curious, will there be much difference between TCP and HTTP requests (with PHP query)? If there will be a lot of difference, how can I make the TCP connection easier? Because I usually used PHP and I always made queries through PHP. I don't know if it's easier or because I'm used to it. What I want is to actually use the PHP query with MySQL again, but I want to provide the TCP connection if this possible. What is your advice about this, what do you think I should do? By the way, I'm sorry about my bad English.

    Thank you.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The typical real time networked game is totally different than a http request approach. Typically you have a server (which can also be a "host" meaning a player in the game acting as both server and client) which is running the simulation. The server sends updates to all clients, with whatever information they need, so the client can properly represent the state of the server to each player. The clients send requests to the server to manipulate that player's character or whatever the player controls in the game. UDP is the most common protocol.

    This is significantly different from a game where the server isn't actually running a simulation, can't proactively send anything to clients on its own, and only responds to client requests which is how I expect your http request approach works out as.

    I'd suggest taking a look at some of the available networking libraries discussed here on the forum, and possibly trying some of them out. You'll see the difference.
     
    Crazy34 likes this.
  3. Crazy34

    Crazy34

    Joined:
    Jul 14, 2019
    Posts:
    69
    Thanks for the advice. I will try the UDP connection. In fact, exactly how do I connect to the UDP method using PHP. In what name or method should I look for this connection format? I want it because I can use PHP at an advanced level. I can also communicate with the MySQL database. Is there a network method for this?

    I'm sorry if I've asked too many new questions. In my research, everyone is able to create varieties in different ways. Unfortunately, I want to make the right connection with the tools(PHP, MySQL). Thank you.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    PHP is really the wrong tool for a real time game's server using UDP. You'd create a build, either in Unity or outside of Unity, and either implement an existing network API or implement your own using Sockets.

    https://forum.unity.com/threads/wha...of-available-network-solutions-assets.609088/
     
    Phoenix116, MrsPiggy and Crazy34 like this.
  5. MrsPiggy

    MrsPiggy

    Joined:
    Jun 13, 2018
    Posts:
    154
    As @Joe-Censored mentioned the HTTP approach with PHP is not the way to go. Too slow and laggy. You need a dedicated server for multiplayer games that handles TCP and UDP. I usually recommend www.smartfoxserver.com You can get it for free for up to 100 CCU and you can experiment, download all their examples and tutorials and learn how the client-server model works.
    Server-side you can implement your game logic in Javascript and Java.
    Also I would not recommend building your own server solution from scratch unless you have at least a year worth of time to invest in it and enough expertise. good luck