Update of /cvsroot/win32forth/win32forth/doc
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22435
Added Files:
SockServer.htm
Log Message:
Jos: Added: SockServer.htm
--- NEW FILE: SockServer.htm ---
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/xml; charset=iso-8859-1" />
<meta name="GENERATOR" content="DexH v03" />
<style type="text/css">
</style>
<title>
</title>
</head>
<body>
<hr /><h1>Socket Library Extension for Servers
</h1><hr /><h3><i>Tom Dixon
</i></h3><p></p><p>This library is built off of the socket library and provides some
generic support for socket servers. The current implementation is
asycronous, single-threaded and is select-based and does not use
the poll() function.
</p><h2>Socket Event Vectors
</h2>These words are used to define the behavior of the sockets on the
server.<br />
Each event is defined as a word with no stack effects ( -- ).<br />
Defining these vectors applies to the currently active client
connection. If you want to set the default behavior for incoming
client connections, please see 'serv-vecselect'.
<pre><b><a name="0">: OnClose! ( xt -- )
</a></b></pre><p>This word stores a new closure behavior for the socket connection.
</p><pre><b><a name="1">: OnRead! ( xt -- )
</a></b></pre><p>This word stores a new read behavior for the socket connection.
</p><pre><b><a name="2">: OnWrite! ( xt -- )
</a></b></pre><p>This word stores a new write behavior for the socket connection.
</p><pre><b><a name="3">: OnConnect! ( xt -- )
</a></b></pre><p>This word stores a new connection behavior for the socket.
</p><h2>Global Socket Data
</h2>When a socket event is being processed, these words contain are to
be used in obtaining specific information about the request.
<pre><b><a name="4">: servdata ( -- addr )
</a></b></pre><p>Returns a pointer to the user-defined data area associated with
every request. The size of this user area is specified by the
server.
</p><pre><b><a name="5">: servsock ( -- sock )
</a></b></pre><p>Returns the socket that the event has been triggered on.
</p><pre><b><a name="6">: close-client ( -- )
</a></b></pre><p>Closes the current socket at frees up the memory from the server.
</p><h2>Socket Server Words
</h2>A socket server is the listening server that takes requests,
processes them, and closes them.
<pre><b><a name="7">: serv-vecselect ( server -- )
</a></b></pre><p>Selects the server for vector behavior. Directly after this word
is called, default behaviors for the entire server can be specified.
</p><pre><b><a name="8">: sockserver ( datasize p <name> -- )
</a></b></pre><p>This word defines a socket server on port "p" and the size of the
user-defined data area per client.
</p><pre><b><a name="9">: serv-init ( server -- )
</a></b></pre><p>Initializes the server and starts listening for requests.
</p><pre><b><a name="10">: serv-close ( server -- )
</a></b></pre><p>Closes the server - open requests are still able to execute, though.
</p><pre><b><a name="11">: serv-poll ( server -- )
</a></b></pre><p>The meat-and-potatoes function of the socket server. This
word will deal with all incoming socket requests, poll through
and process existing socket requests, and cleanup after closed
requests.
</p><h2>Example Code
</h2>This is a simple test of the socket server code. Typing in the
word 'demo' will start the test. Any incoming request will simply
be printed to the console. (Yes, it's not very useful, but it is
a minmal example of use. Please see other examples that should
be with this file).
<pre>256 8000 sockserver test
test serv-vecselect
:noname servdata 256 servsock sock-read servdata swap type ;
onread!
test serv-init
: demo begin test serv-poll 10 ms key? until ;
|