I'm trying to communicate from a Lisp script to another program by using TCP/IP sockets (with sbcl and the usocket library in a Linux system).
So far I got this code:
(require 'asdf)
(require 'usocket)
(defun start-client ()
( usocket:with-client-socket
(socket stream "0.0.0.0" 30000)
(loop for x in '("1~%" "2~%" "3~%" "4~%" "5~%") do
(format stream x)
(force-output stream)
(sleep 1)
;;(format t "~A~%" (read-line stream))
)
)
)
(start-client)
The code works well with the exception of the commented line:
(format t "~A~%" (read-line stream))
So I'm able to send and receive the messages 1,2,3 ... from the other socket (another program) and send messages back from the other program to lisp. However, when I uncomment the line to read the messages from lisp, the above code seems to stop and wait forever.
It is difficult to tell what your problem is, without knowing the server. Maybe it never terminates the line?
Here is a little demo, using threads to isolate client and server:
The binding of
bt:*default-special-bindings
is necessary so that the threads see the same output stream for the demo messages.As you see, both client and server have a stream that they can read from and write to.