Communication between the client and server is processed through asynchronous processes. This means that, unfortunately, you do not have the "send" function, that you transfer your data to be sent to the server and returns a server response. The reason for this is that network communication can be slow and block all other operations in Emacs, which is a single-threaded program.
To send data to your server, use (process-send-string process string) . The first parameter is your network connection, which Emacs treats as asynchronous processes. Since you have this subprocess object already stored in the pserv variable, you can write:
(process-send-string pserv "(my data (can be (in) (list) form))")
to send a string to the server.
To read the serverβs response, you use the process filter function , which are callbacks that are called with what the server sends back to you. Therefore, you first need to define such a callback function, say:
(defun handle-server-reply (process content) "Gets invoked whenever the server sends data to the client." ...)
This function takes two arguments, the network process and the content data that the server sends. There is one difficult point: the server response can be divided into sub-contents. That is, when the handle-server-reply call is called, the content argument can only contain parts of the server response. It can be called later with subsequent content. Therefore, make sure that you handle this correctly.
To declare your function as a callback, use:
(set-process-filter pserv 'handle-server-reply)
As always, character encoding can be lavash, so consider the following two functions and decide if you need them:
(set-process-filter-multibyte pserv t) (set-process-coding-system pserv 'utf-8 'utf-8)
Be sure to install them before assigning a process filter function.
You may also be interested in examining the status of your network connection, for example, to handle cases where the connection unexpectedly closes. To do this, you can use the so-called sentinel functions, another type of callback through which you receive information about changes in the state of the process:
(set-process-sentinel pserv 'sentinel-function) (defun sentinel-function (process event) "Gets called when the status of the network connection changes." ...)
The event parameter contains information on how the connection status has changed.
I think the Emacs documentation was mentioned earlier . It is definitely worth a read.