You are looking at historical revision 15947 of this page. It may differ significantly from its current revision.

Introduction

A generic multithreaded TCP server.

Example

A simple time-of-day server:

Examples:
(require-extension tcp-server posix)
((make-tcp-server 
  (tcp-listen 6504) 
  (lambda () 
    (write-line (seconds->string (current-seconds))) ) )
 #t)

Author

Felix Winkelmann

License

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:

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.

Requirements

None

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
[parameter] tcp-server-accept-connection-procedure
[parameter] tcp-server-get-addresses-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.

Version History