**** PLEASE DISREGARD THIS FILE. IT IS OUT OF DATE, WRITTEN 1/4/95
**** I PLAN TO UPDATE IT SOON.



Object.Server  0.1 - README
Released 1/4/95
Author: Melvin Smith - Mercer University, Macon GA.
----------------------------------------------------------------------------
Problems, contributions, comments, flames:
E-mail -> mudpp-list@spice.com or msmith@falcon.mercer.peachnet.edu
---------------------------------------------------------------------------- 

What is Object Server?

  Object Server is a C++ class that allows you to create your programs to run 
on the internet without the requirement of being a TCP/IP guru. Even for many
capable C programmers, writing a communication module for a concurrent server
is no small task for the first time. Early versions of the server are
admittedly barebones but it should definitely make your life easier.

What can I use it for?

  If you are trying to write a chatline, MUD, or other internet multi-user
application then this is the perfect foundation.
You can use the object and get right to coding your application. Personnally
I am developing a Multi-User-Dimension and wrote it for that only. As stands
the server defaults to TCP, Inet family. Member functions will be added to
set MOST common socket options. If you would like to use the server but it
doesn't offer an adequate interface then E-mail me about your ideas.

What about portability and stability?

  I make no claims about portability, mainly because I dont have access
to many C++ compilers besides my own. I would expect the code to compile
on most platforms that have "proposed ANSI" C++ support. I use
gcc/g++ 2.5.8 and up. If you find that you must hack the code for ANY
reason to get it to compile or run, PLEASE E-mail me and Ill get it fixed. 

Contributions?

Welcome. Credits will be given. Copyrights will not. Don't mail me
copyrighted code, although you are welcome to copyright any code you
post to the MUD++ list. I just won't use it however.


Copyright?

Read the file 'LICENSE'


C++ ? whats that?

 Basically all you need to know if you JUST want to use the server object and
code your stuff in C is how to define and call the object and members.
A "class" is similar to a C struct. The difference lies in that by default all
members of the a class are private which means you can't directly access the
data with struct access such dummy.count = 5, etc. This can be overidden by
defining the data under the "public:" area in the class definition. The other
addition which is also a capability of struct's in C++, is the concept of member
functions. The member functions are accessed in a similar way as data in structs.
You dont worry about manipulating any internal data, just use the object as is
and call the interfaces. Example, the server is booted and I want to find out
the hostname of a descriptor...
 
Server myserver;

then I do something like..

myserver.boot( 4000 );

The functions are called like accessing data in a struct.
Also in the object oriented design theory, you dont set data members directly,
but instead provide an interface for setting and getting. The reason is
not to keep private data from unauthorized programmers (right) but to enforce
good encapsulation and design. Data members of the class can be put into the
"public" section of the class definition and sometimes this is done for
simplicity, but this is usually a sign that the programmer is dropping back to
the C standard of design.
----------------------------------------------------------------------------
Step-by-Step (demo.cc)

First print out a copy of demo.cc to read along with.
Compile the demo with 'make demo'

 I have included a quick little hack of a C++ main() that creates a server
object and uses it as an "echo server". This just accepts connections and
echos back to the user the input. Also supports multiple connections so when
you type something, all other connections get it too. (Chat server in a box!)


1) Creating the server.
   You must #include "server.h" to make use of it.
   Also compile server.cc and link it against your main module or
   create a Makefile.
   
   In your program you must create an instance (actual object) of the Server
   class. There are several ways to do it. Make sure it is either global,
   in top level main() or static (you dont want it to be destroyed until your
   program exits).

   The easiest way is making an instance in main like this...

   Server server(4000);

   To do dynamic allocation use the C++ method, "new"...

   Server *server = new Server(4000);

   Notice the parentheses. This is a C++ constructor. This is just a function
   that is executed each time an object is created. The function is local to 
   that object. This is passing the PORT # that you want your server to run
   on. It is possible to have a port allocated to you by passing a PORT of
   less than 1024 (this is reserved range). Not much support though if you
   request an auto port. Generally user defined apps use a set PORT to keep
   things consistent for the clients. The default port is 4000 so you can also
   do this:

   Server server;  (This will boot on PORT 4000) 

   OK (Dont I ramble? Maybe someone else will write an app and a good README)
   
2) Wasn't that easy. Now all you do is call the member function Boot()...

   server.boot( 4000 );

   You should get some mesages, you will know if the server booted or not.
   You may notice that in my code I also do :

   server.useNameServer();

   If you have a reliable name server you may want to do this in your app also
   but there can be problems if your nameserver is slow. This can cause the
   program to hang sometimes. Just try it, if you have problems then delete
   the call, you will still get numerical IP addresses (111.222.333.444)
   when calling server.GetHostName( desc );

3) If all is successful you can now accept connections. Basically I start
   an infinite loop of polling the server. 

   server.poll();

   You need to call this each time through to update the server on who is
   ready to read, write, or if there is new connection.

4) To check for new connections do something like...
 
   if( server.newConnection() )

5) then if so, call...

   desc = server.accept();

   This returns a small integer value, it is identical as a file handle in
   BSD systems. If you want multiple users, make some type of data structure
   to hold the descriptors. I used an array of ints. To read and write from
   the specific connection you have to have that desc value. You call
   server.Read(desc, buf) where buf is a character array to put the read 
   stuff in, make sure the buf is at least MAX_READ in server.h...
   
6) To boot someone off call

   server.Close( desc );

   Remember the only key you have to access the connection is that int value
   returned by Accept(), just like file IO.

7) Dont worry about cleaning up the server, providing you exit normal either
   with en actual exit() or not, the object destroys all its stuff and
   closes the socket.

8) I apologize for the brevity of this README and the incompletenss of the
   server but I hardly have time to do anything as it is.



NOTE: You can run into some problems if you dont order your calls right.
About the only thing that may happen is this:


FUTURE:
Another class needs to be developed to replace the 'descriptor'
interface. This class could be SocketStream or such, that has
operators like iostreams.

Good Luck!!
Melvin Smith
msmith@falcon.mercer.peachnet.edu