Subject: [clisp-list] problems with sockets on windows

From: James Amundson <[email-masked]>
Date: Tue Feb 17 18:41:02 2004

Maxima is now working with Clisp on Windows. However, I can't seem to
get the socket-based communication between maxima and xmaxima to work.
The same code works with GCL on Linux and Windows. Clisp works under
Linux, but not Windows. Either clisp socket code is broken under
windows, or I am missing something.

The way it is supposed to work is this: maxima starts in server mode by
invoking (setup-server 4008 "localhost"). (The code is attached below.)
xmaxima (a tcl application) then connects to the socket on port 4008.
Using clisp under windows, xmaxima never manages to connect to the
socket.

Any ideas?

Thanks,
Jim Amundson

(defun setup-server (port &optional (host "localhost"))
  (let* ((sock (open-socket host port)))
    (setq me sock)
   #+gcl (setq si::*sigpipe-action* 'si::bye)
    (setq *socket-connection* sock)
    (setq *standard-input* sock)
    (setq *standard-output* sock)
    (setq *error-output* sock)
    (setq *terminal-io* sock)
    (format t "pid=~a~%"        (getpid))
    (force-output sock)
    (setq *debug-io* sock)
    (values)
    ))

;;; from CLOCC: <http://clocc.sourceforge.net>
(defun open-socket (host port &optional bin)
  "Open a socket connection to HOST at PORT."
  (declare (type (or integer string) host) (fixnum port) (type boolean
bin))
  (let ((host (etypecase host
                (string host)
                (integer (hostent-name (resolve-host-ipaddr host))))))
    #+allegro (socket:make-socket :remote-host host :remote-port port
                                  :format (if bin :binary :text))
    #+clisp (socket-connect port host :element-type
                                 (if bin '(unsigned-byte 8) 'character))

    #+cmu (sys:make-fd-stream (ext:connect-to-inet-socket host port)
                              :input t :output t :element-type
                              (if bin '(unsigned-byte 8) 'character))
    #+gcl (si::socket port :host host)
    #+lispworks (comm:open-tcp-stream host port :direction :io
:element-type
                                      (if bin 'unsigned-byte
'base-char))
    #-(or allegro clisp cmu gcl lispworks)
    (error 'not-implemented :proc (list 'open-socket host port bin))))

---

From: Sam Steingold <[email-masked]>
Date: Wed Feb 18 06:29:11 2004

> * James Amundson <[email-masked]> [2004-02-17 20:36:10 -0600]:
>

I don't understand how this can work on linux,
but I take your word for it.

Nevertheless this code is completely and perfectly wrong.

> Using clisp under windows, xmaxima never manages to connect to the

socket _server_ is created by PORT:OPEN-SOCKET-SERVER (which calls
EXT:SOCKET-SERVER in CLISP).
socket stream is created by PORT:SOCKET-ACCEPT (CLISP
EXT:SOCKET-ACCEPT) passively or PORT:OPEN-SOCKET (CLISP
EXT:SOCKET-CONNECT) actively.

>   (let* ((sock (open-socket host port)))
                 ^^^^^^^^^^^^^^^^^^^^^^^ replace with
                 (open-socket-server port)

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Save the whales, feed the hungry, free the mallocs.

---

From: James Amundson <[email-masked]>
Date: Sat Feb 21 10:14:04 2004

> > windows, or I am missing something.

OK. I apologize for bother the list. I *was* missing something...

> Nevertheless this code is completely and perfectly wrong.

I inherited this code. Its most confusing aspect is that it runs a
"server" using a socket client, the "client" is connected via a socket
server. I should have explained the terminology confusion.

> >     (format t "pid=~a~%"        (getpid))

What I was missing is the time bomb in the line
	(setq *error-output* sock)
If there is ever an error with the socket, it sends an error message to
the socket, which generates an error message, which it sends to the
socket, which generates an....

It just turns out that I was getting a perfectly reasonable error that
only showed up using clisp on win32. The error tripped the time bomb.

Sorry for the false alarm.

--Jim Amundson