Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sockets with SBCL and sb-bsd-sockets

443 views
Skip to first unread message

ccc31807

unread,
Dec 5, 2012, 1:07:28 PM12/5/12
to
If I knew what I was doing, I wouldn't need to make this post, but I don't know what I'm doing, therefore I'm making this post.

This relates to communication between two machines. Here is some code I shamelessly stole from the internet, which works for CLISP.

The question is: how do I get this to work on SBCL? The console output is copied below.

Thanks, CC.

ON THE SERVER CONSOLE IN CLISP
[7]> (socket-server-close *socket*)
NIL
[8]> (defparameter *server* (socket-server 9998))
*SERVER*
[9]> (defparameter *server-stream* (socket-accept *server*))
*SERVER-STREAM*
[10]> (read *server-stream*)
"This is CLIENT calling SERVER"
[11]> (print "This is SERVER responding to CLIENT" *server-stream*)
"This is SERVER responding to CLIENT"
[12]> (socket-server-close *server*)
NIL
[13]>

ON THE CLIENT CONSOLE IN CLISP
[8]> (defparameter *client-machine* (socket-connect 9998 "127.0.0.1"))
*CLIENT-MACHINE*
[9]> (print "This is CLIENT calling SERVER" *client-machine*)
"This is CLIENT calling SERVER"
[10]> (read *client-machine*)
"This is SERVER responding to CLIENT"
[11]> (close *client-machine*)
T
[12]>

ON SBCL CONSOLE
* (require 'sb-bsd-sockets)

NIL
* (defparameter *sbcl-socket* (sb-bsd-sockets:socket-bind 9997 "127.0.0.1"))

debugger invoked on a SIMPLE-ERROR:
There is no applicable method for the generic function
#<STANDARD-GENERIC-FUNCTION SB-BSD-SOCKETS:SOCKET-BIND (2)>
when called with arguments
(9997 "127.0.0.1").

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [RETRY] Retry calling the generic function.
1: [ABORT] Exit debugger, returning to top level.

((SB-PCL::FAST-METHOD NO-APPLICABLE-METHOD (T))
#<unused argument>
#<unused argument>
#<STANDARD-GENERIC-FUNCTION SB-BSD-SOCKETS:SOCKET-BIND (2)>
9997
"127.0.0.1")
0] top

* (defparameter *sbcl-socket* (socket-bind 9997 "127.0.0.1"))

; in: DEFPARAMETER *SBCL-SOCKET*
; (SOCKET-BIND 9997 "127.0.0.1")
;
; caught STYLE-WARNING:
; undefined function: SOCKET-BIND
;
; compilation unit finished
; Undefined function:
; SOCKET-BIND
; caught 1 STYLE-WARNING condition

debugger invoked on a UNDEFINED-FUNCTION:
The function COMMON-LISP-USER::SOCKET-BIND is undefined.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

("undefined function")
0] top

*

Daniel Rupis

unread,
Dec 5, 2012, 1:46:30 PM12/5/12
to
;;; the ip-addresses in sbcl are denoted by vectors not strings.

;;;http://www.sbcl.org/manual/INET-Domain-Sockets.html#INET-Domain-Sockets

(require :sb-bsd-sockets)
(defparameter *client* nil)
(defvar *client-stream* nil)
(defparameter *sbcl-socket* nil)

(setq *sbcl-socket* (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol
:tcp))



;; ip-address is a vector, first the host then the port.
(sb-bsd-sockets:socket-bind *sbcl-socket* #(127 0 0 1) 9997)
(sb-bsd-sockets:socket-listen *sbcl-socket* 5)
(setq *cliente* (sb-bsd-sockets:socket-accept *sbcl-socket*))

;;; to connect to a server use (sb-bsd-sockets:socket-connect ip-vector port)

Pascal J. Bourguignon

unread,
Dec 5, 2012, 2:32:57 PM12/5/12
to
ccc31807 <cart...@gmail.com> writes:

> If I knew what I was doing, I wouldn't need to make this post, but I
> don't know what I'm doing, therefore I'm making this post.
>
> This relates to communication between two machines. Here is some code
> I shamelessly stole from the internet, which works for CLISP.
>
> The question is: how do I get this to work on SBCL? The console output
> is copied below.

You don't.

Stop being silly! Use a portability library, so that your program can
work with ANY CL implementation!

http://cliki.net/site/search?query=socket



--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
0 new messages