John
Hi write now i am writing code in c as all the code present in tuxmath is present in c.
Ok. I have a C++ library which is “more or less” independent of Felix which provides
notification services (i.e. tells you when a socket is ready for I/O).
However there are several other libraries around, written in C, and which are
probably better.
One of these is libevent2:
This library covers a lot more than sockets, it provides for all kinds of events including
files being changed, keyboard, etc etc. Last I read, libevent2 uses non-optimal OS functions
to avoid bugs with non-socket events (uses select on Mac or something because kqueue
is bugged for file descriptors … but AFAIK it works fine for sockets). The main downside of
this library (if I recall correctly) is that it is NOT a library. Grrrr… It’s a framework, i.e. all your
code has to be callback driven. Still, that’s not a problem if you run it inside a service thread,
since that has to loop anyhow. It is worth looking at the performance graphs: SDL_net uses
select, see how bad that is.
Another library modelled on libevent is
http://software.schmorp.de/pkg/libev.html
https://github.com/brimworks/libev
These libraries don’t do I/O. They just tell you when sockets are ready.
[Actual socket I/O is trivial].
Again, if you’re doing message handling, look at ZeroMQ. Typically games
do message handling. ZeroMQ handles both point to point and broadcast.
Do not underestimate how HARD it is to send a message on top of the
C socket interface. Better to use code written by someone dedicated to solving
that one problem than inventing the wheel.
Finally … IMHO from a brief look, SDL_net should be fine for a client application
and is probably OK for a server supporting, say, 8 players… just don’t try to
write an improved version of Battle.net with it … As mentioned, you can use
SDLNet_CheckSockets, which uses select, to get rid of your CPU hogging
problem.On 14/03/2011, at 6:18 PM, deepak aggarwal wrote:
–
john skaller
@john_skaller