13

So, I'm trying to set up emacs as a server but I'm having trouble getting it to work from the terminal. If I run emacs --daemon on some terminal I can connect to it if I run the emacsclient from that same terminal, but if I open a new terminal the emacsclient will not find the server. Things seem to work well if I run emacsclient from the launcher.

I am running

emacsclient -a '' -t

The client says:

emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".

Any ideas of what could be happening?

I am using ubuntu 17.04 with gnome/i3 if that matters.

5 Answers5

9

Make sure you are using the same version of emacs and emacsclient.

When my system emacsclient is used instead of my custom build emacs, I'm getting a similar error:

$ /usr/bin/emacsclient --version
emacsclient 22.1

$ /usr/bin/emacsclient .
/usr/bin/emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".

With the correct version:

$ /usr/local/bin/emacsclient --version
emacsclient 26.0.50

$ /usr/local/bin/emacsclient .
Waiting for Emacs...
Toon Claes
  • 246
  • 1
  • 7
  • 1
    This solves my problem – xtt Dec 10 '17 at 15:24
  • Yes that solves mine too. I just recently upgrade my emacs version from 25 to 27, but the `emacsclient` link was pointing to the old version. So `sudo update-alternatives --config emacsclient` to update the links. – ABu Dec 24 '20 at 13:04
5

I used to have the same issue until I did:

alias e="emacsclient -t --socket-name=/tmp/emacs1000/server"

And now I just use this "e" alias to start emacsclient.

I haven't seen the issue since.

izkon
  • 1,798
  • 10
  • 23
  • 1
    This worked, how do I tell the server to start the /tmp/emacs1000/server ? (the first client is starting it for me) – Matías Guzmán Naranjo Sep 27 '17 at 18:04
  • Before running an emacsclient, I always first start the emacs server as `emacs --daemon` and it always starts listening on that `/tmp/emacs1000/server` socket automatically. I'm sure there's a less hacky way to do this that doesn't involve hardcoding the `/tmp/emacs1000/server` location in the `e` alias, and would always work no matter where the socket is created by the server (and that is probably how emacsclient is intended to work when invoked without the `--socket-name` option), but doing it this simple hackish way always worked for me. – izkon Sep 27 '17 at 18:23
  • @MatíasGuzmánNaranjo Using command like `lsof -w -c emacs | grep 'server'` you'll know what the exact socket-name is, and if you are using emacs-28, you'll notice that the socket-name is not `/tmp/emacs1000/server` anymore, it is `/run/user/1000/emacs/server` – CodyChan Dec 11 '20 at 13:51
  • mine is under `/usr/lib/x86_64-linux-gnu/libwayland-server.so.0.1.0` is it normal? – alper Mar 03 '21 at 23:09
5

For unfathomable reasons, this just happened to me on a FC28 upgrade of my laptop. Even stracing ddid not help. After perusing several links (this included), I came up by sticking these lines:

# bash syntax
# On laptop, emacscclient cannot find emacs socket any longer (after FC28)
export EMACS_SERVER_SOCKET=${TMPDIR:-/tmp}/emacs$(id -u)/server
alias emacsclient="/usr/bin/emacsclient -s $EMACS_SERVER_SOCKET"

Which does not hardcode the '1000' part (which just happpens to be the id of the first user created on this particular machine, duh), and accounts for TMPDIR. Exporting EMACS_SERVER_SOCKET is cute, but useless, as emacsclient does not allow that to be configured from an env var (unreasonably, IMHO).

If full control is preferred, one can put:

(setq server-socket-dir "~/.emacs.d/server-dir") 

somewhere before server-start in their .emacs, and use "~/.emacs.d/server-dir/server" as the server socket name for the above mentioned alias. server-dir will be automatically created, with the right permissions 0700, if it does not already exist.

Alien Life Form
  • 181
  • 1
  • 7
1

Not necessarily the answer you are looking for, but I have in exactly the same setup always used just emacsclient -c or emacsclient -t. Meaning I don't start the server manually, the first invoking of either will start the server and any subsequent invoking will connect to the server.

gaussian
  • 46
  • 2
-2

Create a script say "myemacs" as below:

#!/bin/bash
emacsclient -a '' -c "$@"

Run it will create daemon if not exist, and will connect to daemon if daemon exist.

lucky1928
  • 1,622
  • 8
  • 28