1

I made my first attempt at OSC with (Doom) Emacs. I got the example in osc.el working, but I couldn't make it either send or receive messages to/from other processes, even if they are running in Emacs itself (I tried SuperCollider both with Emacs and SCide). I can send OSC with SuperCollider in Emacs to a Python OSC server running in a terminal, but not to the elisp script, or from the elisp script to the Python server.

Here's my code:

(require 'osc)
(setq tkt-osc-client (osc-make-client "localhost" 7770))
(setq tkt-osc-server (osc-make-server
                      "localhost" 7770
                      (lambda (path &rest args)
                         (message "Unhandled: %s %S" path args))))

(osc-server-set-handler tkt-osc-server "/tkt" (lambda (path &rest args) (message "Received: %s %S" path args)))

(osc-send-message tkt-osc-client "/tkt" 1.5 1.0 5 "alo")

;; (delete-process tkt-osc-client)

(provide 'tkt-osc)

What am I missing?

Thanks,

EDIT: I managed to send messages to another process with:

(require 'osc)
(setq tkt-osc-client nil)
(setq tkt-osc-server nil)

(setq tkt-osc-server (osc-make-server
                      "localhost" 7770
                      (lambda (path &rest args)
                        (message "Unhandled: %s %S" path args))))

(osc-server-set-handler tkt-osc-server "/tkt" (lambda (path &rest args) (message "Received: %s %S" path args)))

(defun tkt-make-client (host port)
  (make-network-process
   :name "OSC client"
   :host host
   :service port
   :type 'datagram
   :family 'ipv4))

(defun tkt-osc-connect (host port)
  "Connect to a remote HOST with PORT."
  (if tkt-osc-server (delete-process tkt-osc-server))
  (if tkt-osc-client (delete-process tkt-osc-client))
  (setq tkt-osc-client (tkt-make-client host port)))

(defun tkt-osc-close ()
  (delete-process tkt-osc-client)
  (delete-process tkt-osc-server))

(provide 'tkt-osc)

But the server part still doesn't receive anything, not even the messages sent from this script's client, which was working before...

Any ideas?

1 Answer 1

1

There seems to be a problem with the default osc-make-server function. By adding the property :familiy 'ipv4 to the (make-network-process) function it seems to work.

Here's the full working code:


(require 'osc)
(setq tkt-osc-client nil)
(setq tkt-osc-server nil)

(defun tkt-make-osc-server (port default-handler)
  "Listen to OSC messages on PORT."
  (make-network-process
   :name "OSCserver"
   :coding 'binary
   :filter #'osc-filter
   :host "localhost"
   :service port
   :server t
   :type 'datagram
   :family 'ipv4 // <--------------------------- this makes it work
   :plist (list :generic default-handler)))


(defun tkt-make-osc-client (host port)
  (make-network-process
   :name "OSC client"
   :host host
   :service port
   :type 'datagram
   :family 'ipv4))

(defun tkt-osc-connect (host port)
  "Connect to a remote HOST with PORT."
  (if tkt-osc-server (delete-process tkt-osc-server))
  (if tkt-osc-client (delete-process tkt-osc-client))
  (setq tkt-osc-client (tkt-make-osc-client host port))
  (setq tkt-osc-server (tkt-make-osc-server 7770
                                            (lambda (path &rest args)
                                              (message "Unhandled: %s %S" path args)))))

(defun tkt-osc-close ()
  (delete-process tkt-osc-client)
  (delete-process tkt-osc-server))

(provide 'tkt-osc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.