Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: a good method for client/server communication  (Read 3175 times)

0 Members and 1 Guest are viewing this topic.

og_the_trog

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
a good method for client/server communication
« on: July 17, 2014, 03:29:16 am »
Hello everyone!

so the first two times I have tried implementing networking features into a game I did something along the lines of have the client send the server info then the server disperses this information to all clients.

this worked fine, but quickly I realised that I needed a method to define which types of information was being sent and received from both the server and the client, by this I mean the client might send the server the player's x position, but then the server wont know what to do with it, it would just be a random number which could represent anything like the players x or y position or it's velocity etc.

Then I created a kind of "index" that defined what all the types of information being being sent and received meant. So say the client was sending the server it's x position then there would be a 1 at the beginning of the package that the server could then read and thus know what type of information the package contained. and if the client were to send it's y position it would have a 2 at the beginning of the package so the server knew it was a y position that it was receiving.

okay so what my question is really asking is, is there a better way to do this? after having more than a few different types of information being sent and received it started feeling a bit chaotic, or is this the correct method and should I be working on cleaning up my code and making improvements to make it less chaotic?

I'm using UDP and sfml2.0 by the way
« Last Edit: July 17, 2014, 03:30:57 am by og_the_trog »

Strelok

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • GitHub
Re: a good method for client/server communication
« Reply #1 on: July 17, 2014, 03:59:49 am »
This is not a SFML related question and as such doesn't belong in this category. Even though the SFML devs are knowledgeable and willing to help, you should ask in a forum/site about software design or something like that (or at least move the thread in the appropriate section).

og_the_trog

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: a good method for client/server communication
« Reply #2 on: July 17, 2014, 04:18:30 am »
thankyou will do.

 

anything