« ^ »

Emacsにダミーサーバーの機能を追加する

所要時間: 約 1分
(setq http-proc
      (make-process
       :name "TESTING"
       :buffer (get-buffer-create "*TESTING*")
       :command '("python" "foo.py")))


(process-send-string http-proc "OK\r\n\r\n")
(process-send-eof http-proc)
(signal-process http-proc 1)
       

(setq foo (start-process "TESTING" "*TESTING*" "python" "foo.py"))
(process-send-string foo "aaaaaaaaaaaaaaaaaaa\n")
(process-send-eof foo)


(defun http-server-open-edit-buffer ()
  (interactive)
  (switch-to-buffer (get-buffer-create "*HTTP SERVE EDIT*"))
  (json-mode))


(defun http-server-send-region-to-process ()
  (interactive)
  (process-send-region foo (point-min) (point-max))
  (process-send-eof foo)
  (process-send-eof foo))
import sys
import socket

soc = socket.socket()
soc.bind(("0.0.0.0", 3131))
soc.listen(1)

try:
    while True:
        conn, addr = soc.accept()
        buf = conn.recv(1024)
        print(buf.decode())
        print("<CONNECTION WAITING>")
        data = sys.stdin.read().encode()
        conn.send(data)
        conn.close()
        print("<CONNECTION CLOSED>")
finally:
    soc.close()
    print("Closed!!")