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

Author Topic: Best way to send/recieve a set of data?  (Read 3768 times)

0 Members and 1 Guest are viewing this topic.

Haikarainen

  • Guest
Best way to send/recieve a set of data?
« on: August 04, 2011, 08:40:22 pm »
Me and some friends are currently working on a game, and a lot of work is done allready. I'm in head of the programming, and im wondering;

Players will be able to create and customize their own character before they start playing(its a multiplayer rpg), so when this is done the client will send data like visual details(beards, hairstyle) as well as gamespecific details(what class they are(warrior, dwarf, etc), statpoints ).

What would the best way to send this be?
this:
sf::Packet << sf::Uint(class-identifier) << std::string(hairstyle) << etc;

or create a class containing all this configuration, and send it like:
sf::Packet << bleh::CharacterDataSet(this->CurrentData);
by overriding the << and >> ?

Also how would you override the streamfunctions of a Packet in a safe way for own-written classes?

Hope you get what I'm trying to do, any help is much appreciated.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Best way to send/recieve a set of data?
« Reply #1 on: August 04, 2011, 10:36:33 pm »
Quote
What would the best way to send this be?
this:
sf::Packet << sf::Uint(class-identifier) << std::string(hairstyle) << etc;

or create a class containing all this configuration, and send it like:
sf::Packet << bleh::CharacterDataSet(this->CurrentData);
by overriding the << and >> ?

I think it doesn't make a big difference, it's just a matter of hiding the code behind a function or not.

Quote
Also how would you override the streamfunctions of a Packet in a safe way for own-written classes?

What are you afraid of? It's quite straight-forward, just stream the members of the class, like it is shown in the tutorial.
Laurent Gomila - SFML developer

danman

  • Hero Member
  • *****
  • Posts: 1121
    • View Profile
    • Email
Best way to send/recieve a set of data?
« Reply #2 on: August 04, 2011, 11:58:12 pm »
I prefer the first method, because you generally create a server "namespace" (or class if you want) so you have an abstraction structure between your real application and your server-side application.

However, I advise you to write a protocol documentation ;) .
Pointilleur professionnel

Haikarainen

  • Guest
Best way to send/recieve a set of data?
« Reply #3 on: August 05, 2011, 12:04:23 pm »
Quote from: "Laurent"

I think it doesn't make a big difference, it's just a matter of hiding the code behind a function or not.

What are you afraid of? It's quite straight-forward, just stream the members of the class, like it is shown in the tutorial.


Hm ohwell, pretty new to overloading operators, but imma go for it :) Think it's needed as well since some of these classes will contain a lot of information.


Quote from: "danman"
I prefer the first method, because you generally create a server "namespace" (or class if you want) so you have an abstraction structure between your real application and your server-side application.

However, I advise you to write a protocol documentation


The first method being overloading the operator or not? :P It's confusing, i thought overloading it actually would create a sweet abstraction layer between them.

Hehe, as for the documentation its just me who will remember it so im just creating a list of packet identifiers later(currently i send everything with a string first, and then handle the packet according to that string. Later i will probably use sf::Uint8 or something for a identifier for optimization)

danman

  • Hero Member
  • *****
  • Posts: 1121
    • View Profile
    • Email
Best way to send/recieve a set of data?
« Reply #4 on: August 05, 2011, 01:12:28 pm »
this one : sf::Packet << sf::Uint( id ) << std::string(hairstyle) << etc;


in my server, I have python scripts identified by the ID, and I use signal to trigger external evenements like that :

server.SignalChatMessageReceived.connect( sigc::mem_fun( this, &Application::ReceiveChatMessage ) );
Pointilleur professionnel

 

anything