SFML community forums
Help => Network => Topic started by: MickeyKnox 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?
-
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.
-
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?
-
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...
-
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.
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 ;)