[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tcp-listen



On Jan  7, Wojciech Sobczuk wrote:
> hey,
> 
> it would be nice to have an option to tcp-listen on a single IP not
> all (as it is now).  it's probably a simple change..

But you can easily do it in Scheme:

  (define (connection)
    (printf ">>> ~s~%" (read-line)))
  (define (server)
    (define listener (tcp-listen 9999 1))
    (let loop ()
      (let*-values (((i o) (tcp-accept listener))
                    ((_ ip) (tcp-addresses i)))
        (when (equal? ip "127.0.0.1")
          (parameterize ((current-input-port i)
                         (current-output-port o))
            (connection)))
        (close-input-port i)
        (close-output-port o))
      (loop)))

or maybe you want to deny connections?

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!