You are looking at historical revision 19746 of this page. It may differ significantly from its current revision.
A generic multithreaded TCP server.
A simple time-of-day server:
(require-extension tcp-server posix) ((make-tcp-server (tcp-listen 6504) (lambda () (write-line (seconds->string (current-seconds))) ) ) #t)
Copyright (c) 2004, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Documentation[procedure] (make-tcp-server LISTENER THUNK [MAXREQUESTS])
Returns a procedure that, when invoked, will start the TCP server. LISTENER should be a tcp-listener objects as returned by tcp-listen. For every incoming request, a thread will be started and THUNK (a procedure of zero arguments) will be invoked, with the current input- and output-ports bound so that any I/O is done from/to the client connection. If the optional argument MAXREQUESTS is given, then it specifies an upper limit for currently executing requests. The returned server procedure accepts an optional argument that indicates whether some diagnostic messages for incoming requests should be written to the value of (current-error-port). The optional argument may be a string (which will prefix each diagnostic message), or just #t (which results in a default prefix).[parameter] tcp-server-prepare-hard-close-procedure
Parameters containing primitive socket operations. Use these to parameterize the exact behaviour for closing abruptly, accepting connections and getting peer addresses (for example to use the openssl egg in combination with the generic server). The default values are tcp-abandon-port, tcp-accept and tcp-addresses, respectively.
- 1.2: Added parameterized socket-primitives (Contributed by Thomas Chust)
- 1.1: The verbosity argument of the tcp-server procedure may be a string, now.