client.ss
#lang scheme/base
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NET.plt
;;
;; abstraction of common network behaviors and services
;;
;; Bonzai Lab, LLC.  All rights reserved.
;;
;; Licensed under LGPL.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; client.ss - a basic tcp client.
;; yc 9/20/2009 - first version

(require scheme/tcp scheme/contract)

(define-struct client (host port in out (state #:mutable)))

(define (client-connect host port (state #f))
  (let-values (((in out)
                (tcp-connect host port)))
    (make-client host port in out state)))

(define (client-disconnect client)
  (close-input-port (client-in client))
  (close-output-port (client-out client)))

(provide/contract 
 (struct client ((host string?)
                 (port exact-positive-integer?)
                 (in input-port?)
                 (out output-port?)
                 (state any/c)))
 (client-connect (->* (string? exact-positive-integer?)
                      (any/c)
                      client?))
 (client-disconnect (-> client? any))
 )