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

network server question

Whether to use a flavor or a function depends on how many connections
you wish to handle.  A network connection has a certain amount of
state associated with it such as its stream, and whatever application
dependent data is needed.  In NFILE, for example, a connection has a
control stream, several data streams, and status info and a process
for each stream.  If you only need your server to handle one
connection, you can get away with keeping your connection state in
special variables and writing a function for your server.  If you need
to handle several connections at once, it is better to encapsulate
each connection in a flavor and write methods.  

You can also write a function first and convert to using flavors
later.  In a network service I did, I wrote the user end first.  Since
I only needed the user end to handle a single connection, I kept all
state in specials.  The server end of the protocol was symmetric so I
just encapsulated the connection state in a flavor and called the same
functions as the user end.  Of course, I gave the instance variables
identical names as the user end special variables.

As for using the :flavor option, it's a matter of taste.  You can call
whatever function you want in the define-server form as well as create
any flavor instances you need.  The :flavor option just gives one kind
of default behaviour.  You can also avoid the use of flavors
altogether by binding any specials you need in the define-server form
before calling the server function.