
fu7mu4の日記: 12.3 ソケットを使う land of lisp by closure common lisp
land of lisp を ccl/macでやっている。CLISPではなく、CCLでチャレンジ中。
とりあえず、いろいろみたかんじこれであってるっぽい。
CLISPか、USOCKETを使うべきだったんだろうか?
環境:ccl 1.9/macport/mac
ソケット上でメッセージを送る
=====================
------------------ server --------------------
? (defparameter my-socket
(make-socket :type :stream :connect :passive :local-host "localhost" :local-port 7001))
;=> MY-SOCKET
? (defparameter my-stream (accept-connection my-socket))
;=> MY-STREAM ;;;ただしあとで
------------------ client --------------------
? (defparameter my-stream
(make-socket :type :stream :remote-host "localhost" :remote-port 7001))
;=> MY-STREAM
------------------おわり---------------------
クライアント側も :connect :activeをいれてもよいがデフォルトらしいので省略。
remoteとlocalをかえることになかなか気がつかなくて、泣く。
送受信
====
---------------sender ----------------------
(print "hello by stream" my-stream)
(force-output my-stream)
---------------receiver---------------------
(read my-stream)
;=> "hello by stream"
これも force-outputになかなか気がつかなかった。
バッファリングしているのを強制的に出力させている。
遊んだあとはお片付け
===============
---------------client------------------------
(close my-stream)
;=> T
---------------server-----------------------
(close my-stream)
;=> T
(close my-socket)
;=> T
12.3 ソケットを使う land of lisp by closure common lisp More ログイン