Common Lisp sockets

338 views Asked by At

using ccl specifically, I am trying to set up two sockets in the same program to serve as a fifo data structure.

to that end, I've been standing up test code to exercise my understanding of the api, and I now have a problem I can't figure out. The following code snipped sets up two sockets, one listen and one to connect to the listen, and accepts the connection on the listen socket (the accept call waits for a connection to come in before returning, which is what I want in this case), after which we write to one socket and read from the other. the code hangs and I don't know why (I assume its because the sockets aren't connecting).

The code:

(ccl:with-open-socket (lsock :local-port 8008 :connect :passive :address-family :internet) 
    (ccl:with-open-socket (tsock :address-family :internet :remote-port 8008 :remote-host "127.0.0.1") 
       (let ((stream (ccl:accept-connection lsock))) 
          (write "can you see?" :stream tsock)
          (read stream))))
1

There are 1 answers

0
Joshua On BEST ANSWER

turns out the hang was on the read call, because.... I need (stream-force-output) after the write call. tested and works. Sockets also don't seem to close without explicit calls to (close for lsock, tsock and the stream... I wonder if thats a bug? different question though.