;; (check-errors (format nil "(bind ~A ~A)" socket local)
;;               ;; (rawsock:connect socket (rawsock:make-sockaddr :inet 6))
;;               ;; (rawsock:bind    socket (rawsock:make-sockaddr :inet 6))
;;               (rawsock:bind socket local))


(catch 'errors
  (let ((socket (rawsock:socket :inet :dgram :ipproto-ip))
        (remote (rawsock:make-sockaddr :inet #(27 84 127 0 0 1 0 0 0 0 0 0 0 0)))
        (buffer (make-array 4096 :element-type '(unsigned-byte 8) :initial-element 0)))
    (unwind-protect
         (progn
           (let ((bytes (coerce (map 'vector (function char-code) "gimmi infos")
                                '(vector (unsigned-byte 8)))))
             (print remote)
             (print
              (check-errors (format nil "(sendto ~A bytes ~A)" socket remote)
                            (rawsock:sendto socket bytes remote)))
             (print remote))
           (check-errors (format nil "(recvfrom ~A ~A)" socket remote)
                         (rawsock:recvfrom socket buffer remote))
           (print buffer)
           buffer)

      (rawsock:sock-close socket))))



(bind 13 #<SOCKADDR :%DATA #(2 0 214 216 192 168 7 2)>): OS Error on socket 13: [:EINVAL]: Invalid argument
NIL
(sendto 13 bytes #<SOCKADDR :%DATA #(2 0 19 136 194 9 62 110)>): OS Error on socket 13: [:EINVAL]: Invalid argument
NIL

(usocket:socket-connect "mpserver10.flightgear.org" 5000
                        :element-type '(unsigned-byte 8))


#||

(rawsock:sock-close 6)
(rawsock:sock-close 7)

(rawsock:make-sockaddr :inet *address*)
(rawsock:bind socket (rawsock:make-sockaddr :inet #(0 0 0 0  )))

||#


(catch 'errors
  (let* ((local-port  5003)
         (remote-port 5000)
         (socket   (rawsock:socket :inet :dgram :ipproto-ip))
         (address  (rawsock:make-sockaddr
                    :inet (vector (ldb (byte 8 8) local-port)
                                  (ldb (byte 8 0) local-port)
                                  0 0 0 0 0 0 0 0 0 0 0 0)))
         (remote   (rawsock:make-sockaddr
                    :inet (vector (ldb (byte 8 8) remote-port)
                                  (ldb (byte 8 0) remote-port)
                                  0 0 0 0 0 0 0 0 0 0 0 0)))
         (buffer (make-net-fdm-buffer))
         (fdm    (make-net-fdm)))
    (unwind-protect
         (progn
           (check-errors "bind" (rawsock:bind socket address))
           ;; (check-errors "listen" (rawsock:sock-listen socket))
           (loop
              (check-errors (format nil "(recvfrom ~A)" socket)
                            (rawsock:recvfrom socket buffer remote))
              (deserialize fdm buffer)
              (print-fdm fdm))))
    (rawsock:sock-close socket)))
ViewGit