Search Unity

(Not important) How do you send the data from client to server and vice versa?

Discussion in 'Multiplayer' started by G44Gonzalo, Aug 5, 2019.

?

Good or bad idea?

  1. Good

  2. Bad

  3. Meh

Results are only viewable after voting.
  1. G44Gonzalo

    G44Gonzalo

    Joined:
    Apr 11, 2018
    Posts:
    15
    I mean, I can transfer the data, and I have created a functional system, the only thing I wanted to know is if this is how it is as usually done, or if do you do it differently.

    My sistem is for example:
    If client wants to move, the sent data is: 001/username/password/anglex:angley:anglez/speed
    If client wants to jump, the sent data is: 002/username/password
    If clients wants matchmaking: 004/username/password

    If server found a few players and start game: 005/Data of the players...

    Etc.

    The server identifies the first 3 digits and if necessary, collects the information that comes later, separating it by "/" or by ":" (Obviusly the name and password cant have that characters.)


    That is how my game works. Is that the usual? Is a bad or a good idea? Should I use a secret tag instead of the real password? (I use it on my normal games to avoid hackers hacking the passwords)
    Thanks for answering.
     
  2. MrsPiggy

    MrsPiggy

    Joined:
    Jun 13, 2018
    Posts:
    154
    Normally you don't need to specify the identity of a player in the message because the user is already recognized at a lower level by it's session. Which is typically a tcp/udp connection. Also why sending username/pass every time? This is usually done once at login time, otherwise you're wasting bandwidth. Example: the idea of sending a jump request with credentials sounds very weird. I'd say this is not the correct approach.

    What kind of server are you using exactly?
     
  3. G44Gonzalo

    G44Gonzalo

    Joined:
    Apr 11, 2018
    Posts:
    15


    Yes yes, you're right. Since I wrote this I have learned a lot from the servers. If you had answered me before, I would not have understood. So, the part of the numbers I guess is fine. This thread may seem a bit stupid but it really helps me.
    A lot of thanks for answering. :)
     
    MrsPiggy likes this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Sending everything as strings is inefficient. My guess is parsing the string to the various elements, then converting string floats to actual floats will take both more CPU and more bytes over the network than converting everything to a byte array. For things like movement which may be something that happens frequently, it could add up.

    If your game uses a separate login server (you say servers instead of server, so just making a guess you'd have a central server for logging players in, like a master server), then you'd generally want to send the username/password to that server and have it generate a token which the client uses from then on instead of repeatedly sending the username/password. Also as already mentioned, you shouldn't have to continually send login credentials each time unless your game doesn't actually implement sessions or connections.
     
  5. G44Gonzalo

    G44Gonzalo

    Joined:
    Apr 11, 2018
    Posts:
    15
    Ok thanks! I will also consider the float variables.