[ ... most snipped ... ]
Quote:>An interesting question would be to ask Doug Dimitru (sp?): how long
>it took to write just the HTTP piece of Coyote? This is essentially
>what you're doing.
The HTTP part of Coyote is pretty easy (ignoring the work that was
required to get TCP/IP stacks working on native). The hard part is
getting all of the multiple connections and timeout working without
requiring a huge number of processes spinning.
With Apache, you have a thread for each web "connection". In unix,
this means a lot of processes. Unix processes are light weight enough
that you can get away with this. Pick processes are not so sparing.
Do you really want to run a D3 system with 1000 phantoms (or worse,
1000 paid seats) to handle peak load web requests.
The solution in Coyote was to write a low-level "socket" layer that
supports buffering, queueing, intelligent activity timeouts, and a
shared handle approach that allows handles to float from process to
process. This lets D3 (or other mvDBMS products) services a very
large number of concurrent HTTP streams from a much smaller number of
D3 processes.
Coyote is also different from FC in the scope of it's HTTP
implementation. FC is a client to Apache or IIS. It cannot really
handle "raw" HTTP transactions. Coyote is the server so everything
that the server can see is visible to Coyote applications. If you
want the raw HTTP POST string, it is in a variable. If you want to
query the stacks for the remote IP address of the actual network
connection, that is in a variable as well. For web applications, this
is not too different from FC, but when you start trying to talk to
other systems using HTTP as a generalized transport layer, it is
extremely powerful.
Finally, programming web applications in Coyote is very different from
programming web applications in FC. While some of the HTML concepts
are the same, the actual interfaces are very different. FC is
basically an HTML string manipulator that uses subroutines to build
merged HTML output (I know that I am over-simplifying this here).
Coyote comes much closer to merging HTML and Pick/BASIC as a unified
environment. FC applications tend to be littered with hundreds of
calls to the "w3c..." subroutines. You use them for page merges, to
read form variables, etc. Coyote applications tend to be a mix of
HTML and BASIC. Output merges are accomplished by adding BASIC
expressions directly within the HTML. Form field retrievals are
either handled automatically (for persistant applications) or with the
much more natural PL_GETVAR ... statement (PL_GETVAR is a statement
that you use in Coyote applicatons that has the same syntax as a
"READ" statement. Instead of reading an ITEM from a FILE, it reads an
input field from a form).
Finally, Coyote lets you deploy applications with a very different
license model. FC is now free on D3, but I am sure will cost money on
U2, etc. Using FC is not free however. You still need licensed D3
ports. And if you are using the "easy to program" top down FC
environment, you need a D3 port for every concurrent user. This can
make FC applications very expensive and usually prevents you from
using the top-down approach for any type of public internet
application. Coyote is not free. Current pricing ranges from $1495
to $5995 depending on how much traffic you want to be able to support.
This is the equivelent of about 4 to 17 D3 "ports". The actual Coyote
processing runs on "legal" D3 phantoms (by legal I mean that Coyote
does not hack D3 in any way to avoid licensing). This lets you run
literally thousands of persistent, top-down web applications on a
moderately sized D3 system with pretty negligible D3 licensing
requirements.
<soapbox>
I guess my biggest gripe with FC is that it does rely on an external
server. If you look at the industry as a whole, most products are
progressing to the point of having an HTTP server built into the
product. You have Domino for Notes, Oracle's whatever they call it,
nearly every piece of hardware widget you imagine from print servers
to routers are managed with an internal HTTP server, and even the
webmin unix administrator has it's own HTTP server (completely written
in Perl no less). For D3, U2, and jBase to rely on an external server
is a bit of a cop-out and only serves to decrease flexibility,
increase support costs, and slow performance. This is the same as
using Accuterm to transfer files over a serial or TELNET connection
(no disrespect to Pete here). It does work, but you look at it and
think that there must be a more direct way.
</soapbox>
Back to the original topic. Coding an HTTP hit in BASIC is not really
that hard. You basically:
Read the first line of the stream
If it looks like HTTP/0.9 you process it
If it looks like HTTP/1.0 or HTTP/1.1 you continue reading up to the
double CRLF pair (which some browsers send as only LFs)
You parse the header fields
If there is a POST body, you continue to read that many bytes
You de-code the form fields and/or body "unquoting" as you go
This is the input side. On the output side.
You build an output document in a string
Based on this document, you build a reply header (unless you are
processing an HTTP/0.9 request)
You send it down the pipe
If you comm layer can handle the reply all in one call (and can pass
sockets around from process to process), this is pretty easy as the
application can then go off and do other things. If you have to run
single-process, you will need to have one D3 process per socket (which
might be OK, but might be complete ugly).
Fortunately, the HTTP spec is entirely clear-text and easy to
implement in just about any language with decent string handling. I
would highly recommend that in addition to reading the RFCs, you also
look at some packet sniffer dumps to see how other servers and/or
client behave. A lot of behaviours are "legal" by the RFCs, but are
not exactly what you might expect just by reading them. This is
particularily true in the handling of stream close semantics, having
"extra" CRLFs between requests, etc.
Good luck.
--- Doug Dumitru
EasyCo LLC
Doug Dumitru
EasyCo LLC
949 831-4774
http://easyco.com