On 23 Jun 2006, at 18:56, Alexey Dejneka wrote:
> Patrick May <pjm@...> writes:
>> A recent post on Usenet described a problem with socket-send and
>> broadcast messages. I've been playing around with it, but can't seem
>> to crack it. Here's what I've got:
>>
>> (defparameter *broadcast-ip-address* #(192 168 0 255))
>> (defparameter *broadcast-port* 1234)
>>
>> (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 *broadcast-ip-address* *broadcast-
>> port*
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> These should be local address and port, not
> destination.
Ah! Thank you very much. I haven't used UDP broadcast before, so I
expected to be able to bind to the broadcast address and then call
socket-send with no address and port information.
>> (socket-send socket "test" nil
>> :address '(*broadcast-ip-address* *broadcast-port*)))
>>
>> fails with the message: *BROADCAST-IP-ADDRESS* can't be converted to
>> type (SIMPLE-ARRAY (UNSIGNED-BYTE 8) (4)).
>
> A symbol is not an array :-)
Yeah, I caught that after sending my email. Debugging by public
embarrassment is a very effective technique. ;-)
Regards,
Patrick
|