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.

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
    
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 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 at 18:23

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.

share|improve this answer
    
This works for me, but again, within each specific terminal. So, if I start a new terminal, it will start a new server. – Matías Guzmán Naranjo Sep 17 at 14:20
    
Do you have any server specific stuff in your .emacs? If so, I'd comment it out and try again. Otherwise I am out of ideas. – gaussian Sep 17 at 14:24
    
Also: which version of Emacs you are running? My setup works with both Emacs25 (25.1) from the Ubuntu depo and self-compiled Emacs25.2. – gaussian Sep 17 at 14:40
    
I don't think I have anything in the init file. I am running 25.3, but the same happened with 25.2. Also, launching the server with emacs -q --daemon does the same thing. – Matías Guzmán Naranjo Sep 17 at 14:43
    
Out of ideas, sorry. Works in my setup, even with emacs -q --daemon. – gaussian Sep 17 at 14:49

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.

share|improve this answer
    
This does not work. I get the same problem, If I launch it from two different terminals it creates a new daemon each time. – Matías Guzmán Naranjo Sep 19 at 15:38
    
@MatíasGuzmánNaranjo Oh, but I saw you are using "-t", I am using "-c". Did you try "-c" also? – lucky1928 Sep 19 at 18:56
    
that doesn't change anything, it's the same behavior with either -c or -t. The client just can't find the server. – Matías Guzmán Naranjo Sep 19 at 20:45

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...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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