From: John Spragg
Subject: stream sockets in lispworks professional 4.1
Date: 
Message-ID: <3906D2B6.E52F2C1C@bt.com>
Hi,

Does anybody have any small examples of using socket streams
in lispworks professional 4.1 which I can have a look at?
Basically, I just want to set up a simple
client/server relationship on the same machine: the LispWork
Reference is not that forthcoming with code examples.

Many thanks,

 \ john

From: David Bakhash
Subject: Re: stream sockets in lispworks professional 4.1
Date: 
Message-ID: <m3ln21gj39.fsf@alum.mit.edu>
Hey,

John Spragg <···········@bt.com> writes:

> Does anybody have any small examples of using socket streams
> in lispworks professional 4.1 which I can have a look at?
> Basically, I just want to set up a simple
> client/server relationship on the same machine: the LispWork
> Reference is not that forthcoming with code examples.

I got to use ACL before LispWorks, and definately didn't want to port
networking code.  This is the TCP/IP stuff for LispWorks to be
compatible with ACL (mostly, at least).

If you go to:

http://www.franz.com/support/docs/5.0.1/doc/cl/socket.htm

you can read about how to use the SOCKET package with ACL.  They have
examples.  Also, you can use the code below, which is in the public
domain.

I used to think that it was a shame that the Lisp spec didn't support
socket streams at least.  But then again, it's very easy to take an
implementation's socket API and make it look like another API.

good luck,
dave

;; socket.lisp (for Lispworks compatibility with ACL)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (require "comm"))

(defpackage socket
  (:use comm cl user)
  (:export make-socket accept-connection))

(in-package socket)

(defclass socket ()
  ((fd :type fixnum
       :initarg :fd
       :reader fd)))

(defmethod print-object ((socket socket) stream)
  (print-unreadable-object (socket stream :type t :identity t)
    (format stream ·@~d" (fd socket))))

(defclass server-socket (socket)
  ((element-type :type (member signed-byte unsigned-byte base-char)
		 :initarg :element-type
		 :reader element-type)
   (port :type fixnum
	 :initarg :port
	 :reader port)))

(defmethod print-object ((socket server-socket) stream)
  (print-unreadable-object (socket stream :type t :identity nil)
    (format stream ·@~d on port ~d" (fd socket) (port socket))))

(defmethod accept-connection ((server-socket server-socket)
			      &key (wait t))
  (let* ((accept-function (if wait
			      #'comm::get-fd-from-socket
			    #'comm::accept-connection-to-socket))
	 (socket (funcall accept-function (fd server-socket))))
    (if (minusp socket)
	nil
      (make-instance 'socket-stream
		     :socket socket
		     :direction :io
		     :element-type (element-type server-socket)))))

(defun make-socket (&key (remote-host "localhost")
			 local-port
			 remote-port 
			 (connect :active)
			 (format :text))
  (check-type remote-host string)
  (let ((element-type (ecase format
			(:text 'base-char)
			(:binary 'signed-byte))))
    (ecase connect 
      (:passive
       (make-instance 'server-socket
		      :port local-port
		      :fd (comm::create-tcp-socket-for-service local-port)
		      :element-type element-type))
      (:active
       (comm:open-tcp-stream remote-host remote-port
			     :direction :io
			     :element-type element-type)))))

(defmethod close ((socket server-socket) &key abort)
  (declare (ignore abort))
  (let ((rv (comm::close-socket (fd socket))))
    (zerop rv)))
From: Jochen Schmidt
Subject: Re: stream sockets in lispworks professional 4.1
Date: 
Message-ID: <39079222.F5228956@gmx.de>
John Spragg wrote:
> 
> Hi,
> 
> Does anybody have any small examples of using socket streams
> in lispworks professional 4.1 which I can have a look at?
> Basically, I just want to set up a simple
> client/server relationship on the same machine: the LispWork
> Reference is not that forthcoming with code examples.
> 
> Many thanks,
> 
>  \ john

It would be nice if you could use the "port" package of the
CLOCC Library (See sourceforge.org) so your networking code
would be portable.
As I remember it supports lispworks beside of some other
commonlisp (like cmucl,clisp,AllegroCL...)

-- 
cya,
Jochen Schmidt
···@dataheaven.de
http://www.dataheaven.de