Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- lisp-zmq on Clozure CL: all the functions from its "beginner's guide" fail like this
- CL-USER> (ql:quickload "zmq")
- To load "zmq":
- Load 1 ASDF system:
- zmq
- ; Loading "zmq"
- ("zmq")
- CL-USER> (defun publisher ()
- (zmq:with-context (context 1)
- (zmq:with-socket (socket context :pub)
- (zmq:bind socket "tcp://*:8999")
- (loop (let ((data-string (format nil "~d" (random 100))))
- (zmq:with-msg-init-data (message data-string)
- (zmq:send socket message))
- (format t "Publisher sent ~a~%" data-string))))))
- PUBLISHER
- CL-USER> (publisher)
- NIL is not of type (OR SYMBOL
- FUNCTION), and can't be FUNCALLed or APPLYed
- [Condition of type TYPE-ERROR]
- Restarts:
- 0: [RETRY] Retry SLIME REPL evaluation request.
- 1: [*ABORT] Return to SLIME's top level.
- 2: [ABORT-BREAK] Reset this thread
- 3: [ABORT] Kill this thread
- Backtrace:
- 0: (ZMQ::CALL-FFI -1 NIL #<A Foreign Pointer #x7F2F98015550> #<A Foreign Pointer [stack-allocated] #x7F2FBCA19B60> 0)
- 1: (PUBLISHER)
- 2: (CCL::CALL-CHECK-REGS PUBLISHER)
- 3: (CCL::CHEAP-EVAL (PUBLISHER))
- -- cl-zmq on sbcl: I try to compile the two first functions from the example at http://www.cliki.net/cl-zmq but they fail
- CL-USER> (ql:quickload "zeromq")
- To load "zeromq":
- Load 1 ASDF system:
- zeromq
- ; Loading "zeromq"
- ("zeromq")
- CL-USER> (defun client ()
- "Connects to a socket and passes a message and waits to receive the
- \"OK\" from the server."
- (zmq:with-context (ctx)
- (zmq:with-socket (socket ctx zmq:req)
- (zmq:connect socket "tcp://localhost:5555")
- (zmq:send socket (make-instance 'zmq:msg
- :data "Hello" ))
- (let ((result (make-instance 'zmq:msg)))
- (zmq:recv socket result)
- (format t "Received string: '~A'~%"
- (zmq:msg-data-as-string result) )))))
- ; in: DEFUN CLIENT
- ; (ZEROMQ:WITH-SOCKET (SOCKET CTX ZEROMQ:REQ)
- ; (ZEROMQ:CONNECT SOCKET "tcp://localhost:5555")
- ; (ZEROMQ:SEND SOCKET (MAKE-INSTANCE 'ZEROMQ:MSG :DATA "Hello"))
- ; (LET ((RESULT (MAKE-INSTANCE 'ZEROMQ:MSG)))
- ; (ZEROMQ:RECV SOCKET RESULT)
- ; (FORMAT T "Received string: '~A'~%" (ZEROMQ:MSG-DATA-AS-STRING RESULT))))
- ; --> LET
- ; ==>
- ; (ZEROMQ:SOCKET CTX ZEROMQ:REQ)
- ;
- ; caught WARNING:
- ; undefined variable: ZEROMQ:REQ
- ;
- ; compilation unit finished
- ; Undefined variable:
- ; ZEROMQ:REQ
- ; caught 1 WARNING condition
- CLIENT
- CL-USER> (defun server ()
- "Bind to socket and wait to receive a message. After receipt,
- return the message \"OK\"."
- (zmq:with-context (ctx 1)
- (zmq:with-socket (socket ctx zmq:rep)
- (zmq:bind socket "tcp://lo:5555")
- (loop
- (let ((query (make-instance 'zmq:msg)))
- (zmq:recv socket query)
- (format t "Recieved query: '~A'~%"
- (zmq:msg-data-as-string query) ))
- (zmq:send socket (make-instance 'zmq:msg :data "OK")) ))))
- ; in: DEFUN SERVER
- ; (ZEROMQ:WITH-CONTEXT (CTX 1)
- ; (ZEROMQ:WITH-SOCKET (SOCKET CTX ZEROMQ:REP)
- ; (ZEROMQ:BIND SOCKET "tcp://lo:5555")
- ; (LOOP
- ; (LET (#)
- ; (ZEROMQ:RECV SOCKET QUERY)
- ; (FORMAT T "Recieved query: '~A'~%" #))
- ; (ZEROMQ:SEND SOCKET (MAKE-INSTANCE 'ZEROMQ:MSG :DATA "OK")))))
- ;
- ; caught ERROR:
- ; during macroexpansion of
- ; (ZEROMQ:WITH-CONTEXT (CTX 1)
- ; (ZEROMQ:WITH-SOCKET #
- ; #
- ; ...)).
- ; Use *BREAK-ON-SIGNALS* to intercept.
- ;
- ; error while parsing arguments to DEFMACRO ZEROMQ:WITH-CONTEXT:
- ; too many elements in
- ; (CTX 1)
- ; to satisfy lambda list
- ; (ZEROMQ::CONTEXT):
- ; exactly 1 expected, but got 2
- ;
- ; compilation unit finished
- ; caught 1 ERROR condition
- SERVER
- CL-USER>
- -- pzmq on sbcl: it compiles, but I can't seem to get the client or the server to receive any message. The client does seem to send one message, because my server written in C receives one "Hello", but then everything blocks, this looks like a serious crash of SBCL (Control stack guard page temporarily disabled: proceed with caution) . my C server can communicate with my C client.
- CL-USER> (defun zclient (&optional (server-address "tcp://localhost:5555"))
- (pzmq:with-context (ctx)
- (pzmq:with-socket (requester ctx) (:req)
- (write-line "Connecting to server...")
- (pzmq:connect requester server-address)
- (dotimes (i 10)
- (format t "Sending Hello ~d...~%" i)
- (pzmq:send requester "Hello")
- (write-string "Receiving... ")
- (write-line (pzmq:recv-string requester))))))
- ZCLIENT
- CL-USER> (defun zserver (&optional (listen-address "tcp://*:5555"))
- "Translation of http://zguide.zeromq.org/c:hwserver updated for ZMQ 3. "
- (pzmq:with-context nil ; use *default-context*
- (pzmq:with-socket responder :rep
- (pzmq:bind responder listen-address)
- (loop
- (write-string "Waiting for a request... ")
- (write-line (pzmq:recv-string responder))
- (sleep 1)
- (pzmq:send responder "World")))))
- ZSERVER
- CL-USER> (zclient)
- Connecting to server...
- Sending Hello 0...
- Receiving... Control stack guard page temporarily disabled: proceed with caution
- /*hello world server written in C*/
- int zserver(void) {
- void *context = zmq_ctx_new ();
- void *responder = zmq_socket (context, ZMQ_REP);
- int rc = zmq_bind (responder, "tcp://*:5555");
- assert (rc == 0);
- while (1) {
- char buffer [10];
- zmq_recv (responder, buffer, 10, 0);
- printf ("Received Hello\n");
- sleep (1); // Do some 'work'
- zmq_send (responder, "World", 5, 0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment