I'm trying to create a simple network RPC server/client thing in emacs lisp.
So far I have the following (somewhat minimalist) code:
(defun handle-connection (proc msg)
(message (format "connection received payload: %s" msg))
(process-send-string proc "hello, nice to meet you"))
(defun handle-filter (proc msg)
(message (format "got %s from %s" msg proc)))
(defun handle-filter-surfer (proc msg)
(message (format "got %s from %s" msg proc)))
(defun server-sentinel (proc msg)
(cond ((string-match "^open" msg) (handle-connection proc msg))
(t (message "something went wrong"))))
(setq surfer (make-network-process :name "surfer" :server 5 :host 'local
:buffer "surfer" :filter 'handle-filter-surfer
:service 1337 :sentinel 'server-sentinel))
(setq client (make-network-process :name "client" :buffer "client"
:remote [127 0 0 1 1337]))
All these calls seem to work fine.
My problem is the following: I now want to send a message from the client to the server. The documentation only says that to send data to a process, process-send-string
should be used. So naturally I tried to (process-send-string surfer "asdf")
which resulted in:
Debugger entered--Lisp error: (error "Process surfer not running: listen")
process-send-string(#<process surfer> "asdf")
eval((process-send-string surfer "asdf") nil)
Am I doing it wrong? How DO I send a message from the connected client to the server? When connecting client to server, handle-connection
is called and the "hello" string pops up in the clients buffer, so the other way around seems to work. I guess I need to be connected for it to work, but how do I tell emacs that it should use the connected client to send the message to the server process?