From: Martin Raspaud
Subject: Sbcl sockets
Date: 
Message-ID: <449b1ed0$0$9032$626a54ce@news.free.fr>
Hi all,

I've been trying to do broadcasting on sbcl sockets but without any
success so far.

Here is what I do to setup the socket :

;; create the socket
(setf mysock (make-instance 'inet-socket :type :datagram :protocol :udp))

;; make it a broadcast socket
(setf (sockopt-broadcast mysock) t)

;; connect the socket to a broadcast address (and port)
(socket-bind mysock #(192 168 1 255) 1234)


Now I send something :

;; send something on the socket
(socket-send mysock "hi" nil :address '(#(192 168 1 255)))



The last parameter of the socket-send seems to be necessary (otherwise
it complains that no address is specified) but still I have an error
from this.

Does anyone have a clue on what is wrong ?

Thanks

Martin

From: Patrick May
Subject: Re: Sbcl sockets
Date: 
Message-ID: <m2sllwxp6i.fsf@Dagney.local>
Martin Raspaud <········@free.fr> writes:
> I've been trying to do broadcasting on sbcl sockets but without any
> success so far.

     I hacked together a little example of the Chain of Responsibility
pattern (http://www.spe.com/pjm/message-broker.html) in both Java and
Lisp.  It uses SBCL sockets.  The code is available at
http://www.spe.com/pjm/message-broker.lisp.

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc.  | The experts in large scale distributed OO
                       | systems design and implementation.
          ···@spe.com  | (C++, Java, Common Lisp, Jini, middleware, SOA)
From: Martin Raspaud
Subject: Re: Sbcl sockets
Date: 
Message-ID: <449bad09$0$29870$636a55ce@news.free.fr>
Patrick May wrote:
> Martin Raspaud <········@free.fr> writes:
>> I've been trying to do broadcasting on sbcl sockets but without any
>> success so far.
> 
>      I hacked together a little example of the Chain of Responsibility
> pattern (http://www.spe.com/pjm/message-broker.html) in both Java and
> Lisp.  It uses SBCL sockets.  The code is available at
> http://www.spe.com/pjm/message-broker.lisp.
> 

Thanks for the link !

However, what I need to do is to find receptive clients in my network,
so I need to broadcast a message to a broadcast address (like
192.168.255.255 for example) and then send back a message to the
boradcaster.

Apparently your code just recieves message without sending anything...

but thanks anyway.

Martin
From: Patrick May
Subject: Re: Sbcl sockets
Date: 
Message-ID: <m2irmqy2q3.fsf@Dagney.local>
Martin Raspaud <········@free.fr> writes:
> Thanks for the link !
>
> However, what I need to do is to find receptive clients in my
> network, so I need to broadcast a message to a broadcast address
> (like 192.168.255.255 for example) and then send back a message to
> the boradcaster.

     Sorry about that, I read your post too quickly.  To make up for
it, I played around with your problem and, thanks to the help of
Alexey Dejneka on the SBCL mailing list, got the following to work:

(defparameter *local-ip-address* #(192 168 0 3))
(defparameter *local-port* 1234)
(defparameter *broadcast-ip-address* #(192 168 0 255))
(defparameter *broadcast-port* 5678)

(defmacro with-udp-broadcast-socket (socket ip-address port &body body)
  "Create and close a UDP socket configured for broadcast around the body."
  `(let ((,socket (make-instance 'inet-socket
                                 :type :datagram
                                 :protocol :udp)))
     (setf (sockopt-broadcast ,socket) t)
     (socket-bind ,socket ,ip-address ,port)
     (unwind-protect (progn ,@body)
       (socket-close ,socket))))

(with-udp-broadcast-socket socket *local-ip-address* *local-port*
  (socket-send socket "test" nil
               :address (list *broadcast-ip-address* *broadcast-port*)))

I'd only used multicast previously, so this was educational.

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc.  | The experts in large scale distributed OO
                       | systems design and implementation.
          ···@spe.com  | (C++, Java, Common Lisp, Jini, middleware, SOA)