I'd like to use emacsclient on my laptop to connect to an emacs server on my desktop.

I think I know that the emacs server process listens to a unix socket in "/tmp/emacs${UID}".

So I need to make a connection between a unix socket in laptop:/tmp/emacs${UID}/socat to desktop:/tmp/emacs${UID}/server.

I can make a socket locally with socat. I have tested:

socat -v UNIX-LISTEN:/tmp/emacs${UID}/socat UNIX-CONNECT/tmp/emacs${UID}/server
emacsclient -nw -s socat .

That works.

So now I need to connect socat to server on the remote host...

socat -v TCP-LISTEN:7777 UNIX-CONNECT:/tmp/emacs${UID}/server
socat -v UNIX-LISTEN:/tmp/emacs${UID}/socat TCP-CONNECT:
ssh -L9999: desktop
emacsclient -nw -s socat .

I can successfully route traffic over this setup. I know this because my home directory is different on my laptop, and the socat on the desktop is dumping out laptop-home-directory-related paths.

However, the emacsclient process on my laptop doesn't draw a frame.

Is there a way to make this work?

Edit: xuchunyang writes:

By the way, we don't need emacsclient to use the Emacs server, echo '- 
eval emacs-version' | nc -U /path/to/emacs/socket works as well.

I can confirm that connecting to the socket on the laptop works:

laptop $ echo '-eval emacs-version' | nc -U /tmp/emacs248200/socat 
-emacs-pid 184752
-print "26.3"
  • Anticipating one possible question: my username and uid are the same on both hosts. – Realraptor Mar 27 '20 at 14:20
  • I don't know if that's possible: emacsclient just sends stuff to emacs, so it is the remote emacs that would need to create the frame on your laptop, i.e. more plumbing would be needed. Why not run a full emacs on your laptop and use tramp to access stuff on your desktop? – NickD Mar 27 '20 at 14:35
  • Answer 1: emacsclient -nw creates the frame inside the terminal - is the server doing this? – Realraptor Mar 27 '20 at 14:48
  • 1
    Re: Answer 1: probably not, but does that even work for you? The frame is completely unresponsive for me. – NickD Mar 27 '20 at 15:18
  • 1
    Not sure if it's possible, you shouldn't be able to make a graphic frame for sure, but what about text frame? considering we can use Emacs (or any full screen apps) through ssh. By the way, we don't need emacsclient to use the Emacs server, echo '-eval emacs-version' | nc -U /path/to/emacs/socket works as well. – xuchunyang Mar 27 '20 at 15:19

rpluim suggests trying emacsclient-over-tcp.

Adding an answer in order to have formatting available.



(setq server-use-tcp t                                                                                                                                                                   
      server-host ""                                                                                                                                                                
      server-port 6666                                                                                                                                                                       
      server-auth-dir "~/.emacs.d/server"                                                                                                                                                


scp desktop:~/.emacs.d/server/server ~/.emacs.d/server/server
ssh -L 6666: desktop
emacsclient -nw -f ~/.emacs.d/server/server .


The emacsclient call hangs after connecting (exactly the same behaviour as seen trying to tunnel the unix socket). There is a connection to port 6666 on the laptop.

  • 1
    Why are you port forwarding? It's TCP, just have emacs listen on a reachable IP address. – rpluim Mar 28 '20 at 11:43
  • 1
    If you forget about everything else and do just emacsclient -nw, does that work for you? It does not work for me (as I mentioned in a comment: the window is unresponsive), so maybe there is a bug in the emacsclient -nw code - or maybe there is something that I'm missing. – NickD Mar 28 '20 at 15:51
  • rpluim: my employer has non-trivial security measures which mean that a direct connection is harder than port forwarding. – Realraptor Mar 28 '20 at 16:16
  • NickD: "emacsclient -a '' -s <servername> -nw ." is something that I use often - I have 1249 instances in my shell history. This hanging behaviour is completely new to me. – Realraptor Mar 28 '20 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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