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

Author Topic: [SOLVED] Basic Question: Sending Data  (Read 4789 times)

0 Members and 2 Guests are viewing this topic.

m0refi4

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Basic Question: Sending Data
« on: March 30, 2010, 01:10:51 am »
Heya,

I've just found SFML and its great community. I'm pretty new to networkprogramming so I have some basic questions about servers and clients.

Well heres the problem I'm thinking of:

I'll give you an example:
My server contains following class:


Code: [Select]

class Player
{
   private:
   int level;
   
   public:
   int getLevel(); /returns the level
}


The server creates a player now.

Code: [Select]
Player player;

So, how can I call the getLevel() function with the client?

As I said I'm really new to this and I hope someone could help me a little out with this.

Greets

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
[SOLVED] Basic Question: Sending Data
« Reply #1 on: March 30, 2010, 08:34:56 am »
Hi,

Since the client can't see the Server variable, he can't.
What you have o do is creating a protocol between Server and Client in order to make the client be able to ask some informations to the server.
For example :
Client : LIST_PLAYERS
Server : LIST_PLAYERS, Player_1, Player_2, Player_3 (The client will now have a std::vector with those names)

Client : PLAYER_INFO, Player_2, Level
Server : PLAYER_INFO, Player_2, Level, 3 (Thus, the client now knows that the player named Player_2 ahs a level of 3)

etc... ;)
Mindiell
----

m0refi4

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Basic Question: Sending Data
« Reply #2 on: March 30, 2010, 03:34:29 pm »
Thank you Mindiell for your reply!

I'm still kinda stuck at this point:
SFML uses 2 types of sending data between client and server.

Send  (const char *Data, std::size_t Size)
Send  (Packet  &PacketToSend)

I guess I'm supposed to use the one sending the Packet. (Does this even have something to do with the protocol? :P)

So I hope I got your point:
By creatig my own Packet I can send the server what he should do.

Some example:

Client side:
int what_to_do = 1;
//send the server a packet containing the what_to_do
Packet ToSend;
ToSend << what_to_do

Server side:
// get the packet
Packet recieved;
int what_to_do;
received >> what_to_do

if (what_to_do == 1)
{
   // do something...
}

Well I might be totally wrong. If so, is there any step-by-step tutorial out there since I havent found any by now.

Thanks in advance
greets

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
[SOLVED] Basic Question: Sending Data
« Reply #3 on: March 31, 2010, 09:18:13 am »
This is exactly the good way. You can find the SFML tutorial here.

Packet has nothing to d owith protocol, it's just an object created by Laurent for the SFML giving the ability to send lot of things on the network without any questions on Big and Little Endian.

So you can use either Packet or char* (a simple array of bytes finally).

Since you have control over the server and the client, you should use the Packet object.

Do not hesitate to use enum for your commands, and not to let the commands being to much hard in order to add features easily.
Mindiell
----

m0refi4

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Basic Question: Sending Data
« Reply #4 on: April 01, 2010, 12:01:47 am »
Thank you very much for your help.

I understood how the packet was working I just didnt know which way I'm used to handle those packets for the client/server interaction :P

Everythings fine now =)

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
[SOLVED] Basic Question: Sending Data
« Reply #5 on: April 01, 2010, 09:45:29 am »
Good thing,

Don't forget the "[SOLVED]" in the title of your post please ;)
Mindiell
----

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SOLVED] Basic Question: Sending Data
« Reply #6 on: April 01, 2010, 11:05:40 am »
Quote
Don't forget the "[SOLVED]" in the title of your post please

There is not such a rule on these forums ;)
Laurent Gomila - SFML developer

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
[SOLVED] Basic Question: Sending Data
« Reply #7 on: April 02, 2010, 09:45:53 am »
Sure, but it would be so much easier for helping people who need it  :P

*break the rules !*
Mindiell
----

m0refi4

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED] Basic Question: Sending Data
« Reply #8 on: April 02, 2010, 04:08:08 pm »
Quote from: "Mindiell"
*break the rules !*


Done. hehe

Thanks again for the help