1

I've been looking around StackOverflow for a simple network TCP connection in C++ and all I seem to find are Java, Python and C#. I understand that Python or Java can set up easy connections but mostly I am programming a simple Yahtzee game in C++ and wanting to learn about the Networking in C++ because I have about a year's knowledge on C++ but don't have a strong grasp of these other languages, but alas I can't find a good simple set up to suit my needs.

I saw C++ Winsock P2P who has a set up but it has a few points that are tough for beginners.

In my game I am expecting the client to do most of the work (as I've heard that is a better implementation) but am not sure where to have the server take inputs and throw back outputs. I have the client rolling and displaying the rolls. Then I assume it would do all three rolls and once you've chose where to use your rolls, the client sends the server the placement in the score sheet and the dice rolls.

I understand the protocols of: you send something and the server can compute and send it back, but my question is, Do I have my client send a number (int choice = 12 for a yahtzee obviously) as a packet message and then send an array of dice rolls (int roll[5]) for the server to compute what goes in? or should the client do that work? This is what I don't know about the sending and overall set up.

Community
  • 1
  • 1
Chris S
  • 11
  • 3
  • If you're designing the application and protocol, you decide what the best way to do it is. – Barmar Mar 17 '17 at 22:31
  • 1
    If you're implementing a multi-player game, you generally need the server to do most of the work. If you do it on the client, the user can generate fake dice rolls that always give him Yahtzee. – Barmar Mar 17 '17 at 22:32

1 Answers1

0

This question is difficult to answer as it is really just your decision how to do it, and both approaches work. Some general aspects to consider in a server clients system:

  • Stuff that the client does is a lot more vulnurable to hacking. (e.g. If you generate the Random die result on the client, one could change the code and send your server wrong data, like always 12 or whatever)

  • Stuff that you do on the server impacts performance when your user number grows very large. Letting the client do it leaves your server processing power for other stuff

  • Oviously limit the amount of information you send when possible

    So a general rule of thumb would be: let the server do anything that's 'dangerous', let the client do everything else. (Though unfortunately a lot of things are dangerous in this context)

In your case I would let the server do the dice rolling and send the results to the user.

Do I have my client send a number (int choice = 12 for a yahtzee obviously) as a packet message and then send an array of dice rolls (int roll[5]) for the server to compute what goes in? or should the client do that work?

You cant send an empty array and let the server fill that in. Remember, those can be seperate Computers. They cant access each others memory. You could just send a request to the server (Maybe an int constant) so it knows what to do(rolling a dice e.g.) and then listen on the network for data and interpret e.g. the next 5 bytes that the server sends you as the dices it rolled.

Community
  • 1
  • 1
ChrisB
  • 1,540
  • 6
  • 20