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

Author Topic: Using OnSend and OnReceive  (Read 3087 times)

0 Members and 1 Guest are viewing this topic.

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Using OnSend and OnReceive
« on: April 19, 2011, 03:37:27 pm »
I would like to use the SFML Packets, but not the SFML Sockets.
To do this, i thought i could just use the OnSend and OnReceive
methods, in order to feed the packet data to my network library
and vice versa.

However, those methods are private and i can't just call them.
I don't really understand what is the purpose of them being
private.

I guess i could just alter the SFML sourcecode to my needs, but
i would prefer not to do that.

Is there an more elegant approach?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Using OnSend and OnReceive
« Reply #1 on: April 19, 2011, 03:59:06 pm »
Quote
I don't really understand what is the purpose of them being
private.

The purpose is to avoid this kind of situation, where users try to do silly things ;)

Basically, you don't need to call OnSend/OnReceive if you don't subclass sf::Packet. These functions exist only to allow custom processing to happen before sending or after receiving data.
Laurent Gomila - SFML developer

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Using OnSend and OnReceive
« Reply #2 on: April 19, 2011, 04:18:06 pm »
Well, i had a look in SocketTCP.cpp, particularly in the Send(Packet&)
method. The OnSend method of the Packet is called in there, to get
the data. This is possible, because this class is declared a friend
in Packet.

This is basically what i want to do myself.

I don't want to use the Socket class of SFML, but rather another library
(ENet to be specific). I don't think this is a silly thing.

So maybe i shall put my question another way:
How can i get the data in the packet without modifying the SFML source code?

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Using OnSend and OnReceive
« Reply #3 on: April 19, 2011, 04:39:02 pm »
Nevermind, i just found the GetData method in Packet, which is public.

And it actually makes sense, that SocketTCP calls OnSend instead of GetData.

Sorry to bother...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Using OnSend and OnReceive
« Reply #4 on: April 19, 2011, 05:06:44 pm »
Quote
Nevermind, i just found the GetData method in Packet, which is public.

That's what I meant, the default implementation of OnSend and OnReceive does nothing more than forwarding to public functions that you can call directly.

Quote
I don't want to use the Socket class of SFML, but rather another library
(ENet to be specific). I don't think this is a silly thing.

"Silly" was refering to calling OnSend/OnReceive on user side, not using sf::Packet without sf::Socket ;)
Laurent Gomila - SFML developer

 

anything