elisp process-send-string 给出意外错误“进程未运行:监听”

问题描述 投票:0回答:1

我正在尝试在 emacs lisp 中创建一个简单的网络 RPC 服务器/客户端。
到目前为止,我有以下(有点简约)代码:

(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]))

所有这些调用似乎都工作正常。
我的问题如下:我现在想从客户端向服务器发送消息。该文档仅说明要将数据发送到进程,应使用

process-send-string
。所以很自然地我尝试
(process-send-string surfer "asdf")
,结果是:

Debugger entered--Lisp error: (error "Process surfer not running: listen")
  process-send-string(#<process surfer> "asdf")
  eval((process-send-string surfer "asdf") nil)

我做错了吗?如何从连接的客户端向服务器发送消息?当将客户端连接到服务器时,会调用

handle-connection
并在客户端缓冲区中弹出“hello”字符串,因此相反的方式似乎也有效。我想我需要连接才能工作,但是我如何告诉 emacs 它应该使用连接的客户端将消息发送到服务器进程?

networking tcp process emacs
1个回答
0
投票
(process-send-string client "asdf")
;; => got asdf from surfer <127.0.0.1:1337>

我的理解是“客户端”充当套接字,它允许您与服务器交互。

handle-filter
未使用,顺便说一句。

© www.soinside.com 2019 - 2024. All rights reserved.