chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Poker server in Chicken


From: felix winkelmann
Subject: Re: [Chicken-users] Poker server in Chicken
Date: Sun, 5 Dec 2004 15:18:17 +0100

On Sat, 4 Dec 2004 21:56:33 +0000, Joel Reymont <address@hidden> wrote:
> 
> I know PLT Scheme some but I'm totally new to Chicken. My server needs to
> support over 1000+ simultaneous users and I need to squeeze the most out
> of each server. Folks on the #scheme channel suggested that I use Gambit
> but I'm wondering if Chicken would be a better choice. I could not find
> any information on how to save an object (structure) into a sexp in
> Gambit for example.

Yes, Gambit is specifically tuned for high-load multithreading, so it
really might
be a good choice. On the other hand Chicken's threads are also quite efficient,
and there are lots of hooks and low-level tools, and Chicken provides numerous
ways to interface to C/C++. And it has the funnier mascot! ;-)

> 
> -- Should I create structs for my events? For example, game summary
> request when a player is in the lobby would not carry any data but the
> reply would be a list of game summaries.

So you mean, you have structured data with nested items? If the events are
highly structured, it might be nice to send s-exprsessions with embedded
structs that use SRFI-10, like:

(a b c #,(game-summary <summary-data> ...) ...)

> 
> -- How do I introduce field types? I would like a balance field to be a
> float for example. Do I even need to do this or I should I implement the
> portable (endian independent) serialization code in C++ and just query
> the structure fields to figure out how to serialize them?

Scheme structures have no type-information, so you probably better send
the data untyped (as s-exprs, for example), or figure out the type
from the field.

> 
> -- Suppose I "serialize" a struct into a vector. When passing the vector
> to the external C++ code to be sent over the net are there any endian-
> ness issues? How do I avoid them, i.e. store everything big-endian?

Yes, endianness has to be handled in any case, when you use a binary protocol.
I'm not completely sure I understand. Chicken itself provides no serialization
(i.e. to/from binary representation) facilities at all. One either uses text
(s-exprs), or performs the serialization/de-serialization by hand.

> 
> -- Is there an elegant recipe to "register" my structs so that when I get
> a vector from the network C++ code into scheme I could avoid a long
> series of match statements to figure out exactly what kind of a packet I
> received?

Yes, you could use SRFI-10 (as used in the example above). You register
a reader-procedure that will be called when the reader encounters text
of the form "#,(<name> <arguments> ...)". This of course assumes a textual
protocol.

> 
> -- Is there a way to serialize things in some sort of a well-defined
> binary format? I would like to have clients that not only use Scheme but
> are pure C++ or Java for example. I would like to be able to publish the
> protocol and  describe the packet structure by saying here goes the float
> balance and then an integer id follows, etc.

One could write such a thing, but currently it doesn't exist. I would go for
a text-based protocol, but I don't know what performance requirements
you have.  On the other hand serialization of Chicken heap data isn't
such a big deal in itself, it's mostly things like circular data and stuff like
that that makes it complicated. If your protocol doesn't need a fully
general serialization mechanism, writing a custom one shouldn't be too
hard. Just tell me what kinds of data types you want supported.

(BTW, there is an interesting library for parsing s-exprs in C
at http://sexpr.sourceforge.net/ - it's supposed to be very fast and
seems quite simple to use).

Can you give an estimation about the amount of data that is transmitted?
(Sorry, I don't know much about poker, or how it's played online)


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]