replacing ssh+screen+editor with emacs - emacs

My goal is to remotely write code. So far, I have been using ssh + screen + an editor (e.g. vim).
I understand using a local emacs (or vim), one can edit remote files. But once the local emacs is closed and I want to reopen it (or open it using another computer), I would need to reopen all the buffers again.
Is there a way to set up a emacs server on the remote machine and I could simply access it using a local emacs client? Which essentially simulate the screen behavior.

I think you might find your answer here;
http://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html
According to http://www.gnu.org/software/emacs/manual/html_node/emacs/emacsclient-Options.html#emacsclient-Options ;
An Emacs server usually uses an operating system feature called a “local socket” to listen for connections. Some operating systems, such as Microsoft Windows, do not support local sockets; in that case, Emacs uses TCP instead. When you start the Emacs server, Emacs creates a server file containing some TCP information that emacsclient needs for making the connection. By default, the server file is in ~/.emacs.d/server/. On Microsoft Windows, if emacsclient does not find the server file there, it looks in the .emacs.d/server/ subdirectory of the directory pointed to by the APPDATA environment variable. You can tell emacsclient to use a specific server file with the ‘-f’ or ‘--server-file’ option, or by setting the EMACS_SERVER_FILE environment variable.
Even if local sockets are available, you can tell Emacs to use TCP by setting the variable server-use-tcp to t. One advantage of TCP is that the server can accept connections from remote machines. For this to work, you must (i) set the variable server-host to the hostname or IP address of the machine on which the Emacs server runs, and (ii) provide emacsclient with the server file. (One convenient way to do the latter is to put the server file on a networked file system such as NFS.)
When the Emacs server is using TCP, the variable server-port determines the port number to listen on; the default value, nil, means to choose a random port when the server starts.
Of course, make sure to adjust your firewall settings on the server side, so that clients may connect to the machine running the emacs-server.

I've attempted the method mentioned in the other post many times and have never had any success with it.
One nice thing that emacs is able to do is desktop-save-mode which will store all of your open buffers when you kill emacs and restore them when you open emacs again. By default it won't restore tramp buffers, but you can tweak the settings to allow this to happen. More information can be found in this Stack Overflow question.

You can login locally and then ssh to a remote machine. On the remote machine, you can have 'screen session, that you can join'. In this session, you have emacs running, with all buffers as you had left. You can also use the desktop-save in combination to this, in the case that remote machine need to be restarted, and you can lose your session. This is the most practical solution, I use. You can change the 'client computer' any time. You don't need to use local emacs client. You can also make multiple session for different projects and join screen session for a particular project on different terminal.

Related

How does VS Code automatically detect port allocated by the command and start port forwarding it when working remotely?

I know that this question look similar to VSCode [Remote Development] [Forward Port] work? but it isn't.
When I launch a command which starts a web server on a random port (and prints out the url to access it),
VS Code auto detects the newly allocated port and starts port forwarding that port to my host machine.
How does this happen? Does VS Code check for newly allocated port by the current command ? If so, how does the shell script for this look like ?
This has been answered by VSCode developer on github here.
To summarize, VSCode will actively look into the proc file system ie. /proc directory and detect the port that was allocated and then start auto portforwarding it.
Assuming remote.autoForwardPorts is set to true, it depends on the operating system that VS Code is running on.
On Windows and Mac remotes, it picks up from the terminal output (the output option under remote.autoForwardPortsSource):
Note: on Windows and Mac remotes, selecting the process option has no effect and output will be used.
On other operating system remotes, if the process option is selected, VS Code watches for processes that start with a port included, and automatically forwards ports for those:

How to check if inbound port is in use

I'm developing Firefox addon that communicate with external program by sockets. This program create local socket server on specified port when this addon need it. I would like to ckeck from this addon whether this application has opened this port already.
On Win7 when server isn't created yet I receive in socket created by addon NS_ERROR_CONNECTION_REFUSED in nsIRequestObserver::onStopRequest but if I can feel certain port isn't open when I receive this error?
You try to connect and see if the connection succeeds.
If it doesn't, then the port is not reachable (open).
That's the most obvious and easiest answer.
Other low-level solutions would require polling the OS itself somehow. That would be cross platform specific (so you'd need to write an implementation per platform) and also there is no API readily available so you'd have to mess around with C/C++ or at least js-ctypes, or hack together some ugly "execute this program and check output" stuff. All of which doesn't worth the fuzz.
If you want to find out which "inbound ports" are in use in windows you can use cmd,
if you don't know how to open cmd - open the run dialog by pressing windows-key+r. type cmd and hit enter
type netstat -a and hit enter and it will list all "listening" ports.
more info - http://www.techrepublic.com/blog/it-security/list-open-ports-and-listening-services/

send/receiving raw ethernet frames

I've to write an application on Linux that has the requirement to talk with a device with custom Ethernet type. There are many solutions even in SO how to write such an application. A drawback is that for this root access is needed (AFAIK). Releasing the root rights afterwards could be an option, but it raises the problem that the program is developed in an IDE, which I don't like to run as root. In my special case the main application is written in Python which would mean to give root access to the whole Python interpreter. I'm looking into possible alternatives. E.g.
Writing a tiny UDP/TCP server that redirects every raw packet over TCP/UDP. This could be written in Python as well. Only this tiny application needs root rights.
Using socat for redirection, unfortunately I'm unable to find an option to only care about one Ethernet type on not get overflowed by IP packets.
Any other ideas?
I think you only need to be root, or have CAP_NET_RAW, to open the socket. Once the socket is open, you can be any user you like.
So have either:
A setuid helper program which opens a raw socket, binds it (if necessary), then drops its root privileges and exec's your main program, keeping the socket open and passing the file descriptor number somehow (command line? Environment variable?)
A setuid helper which will pass an open file descriptor using another mechanism (e.g. unix socket)
A root-owned daemon which passes such an open socket descriptor to other programs upon request

Is it possible to run matlab on a remote server and control it using the matlab GUI from a thinclient?

Akin to what can be done with emacs with slime: the core services can run on a performace grade remote computer while I can edit and run code from emacs gui on an netbook.
Me and my colleagues often need to do some demos using machine
learning scripts running in matlab
This requires us to carry around heavy laptops.
Could we have the applications running on a remote server and access
it using the same matlab gui without running the scripts locally?
Remote desktop or similar solutions are not acceptable: multiple users would like to use the same server.
This is why none of the answers here were helpful
In my experience, the best way is with VNC. You can start a VNC server on the host machine, and then access this desktop remotely from anywhere with a VNC client. You can disconnect and reconnect at another time, and your desktop will still be there. Also, multiple users can all have different sessions going, or can access the same one. If you don't want each session to run a full blown desktop, you can configure it to be minimal. For security, it is recommended to use an SSH tunnel or similar.
The exact programs will vary based on your setup, but the things to google are bolded, above.
My setup is:
VNC server: vnc4server on a Ubuntu linux host.
VNC client: Chicken of the VNC for mac.
SSH tunnel: SSH Tunnel Manager for mac (although this can be done at the command line too).
Good luck!
EDIT: Here is a screenshot of a vncserver session I just started up on our cluster, with matlab running in it. I'm accessing it through the vnc client on my mac. Works great!
SSH with X-window forwarding will do the trick. It will get you the MATLAB screen you know and love but will be running everything on the remote computer. To do this, in a terminal with SSH (I like MobaXterm, though you can use Putty) you ssh via
ssh server.location.here -X
This will get you the terminal on the computer (after typing in a password), and in the terminal just type
matlab
and a MATLAB screen will show up. Note that opengl will be disabled, so your plots might not plot as fast, though you can still use gpu algorithms (i.e. cuda. Note you may need to run the command "COMPUTE=:0" before opening matlab if gpuDevice turns up empty for MATLAB's cuda).

How can I set the port that the Emacs Server uses?

I use Emacs to do most of my development work, I'd like to be able to connect to the Emacs server running on my office workstation from home. I connect to my office network over a VPN, I think this is mostly safe.
Anyway, I have a script that copies the server authentication file out, but it looks like the port changes every time. Our VPN is pretty locked down, I need to tell our sysadmin what ports I want open to which machines.
Is there a way to set the port that the Emacs server listens on?
Looks like this is now fixed. I'm using Emacs 24.3.1 and there is now a variable server-port:
C-h v server-port RET
gives the following documentation:
Documentation:
The port number that the server process should listen on.
This variable only takes effect when the Emacs server is using
TCP instead of local sockets. A nil value means to use a random
port number.
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 24.1 of Emacs.
so a (setq server-port 12345) in your init file should do the trick.
Someone posted a small patch to allow customizing the server port to the Emacs Bugs list in September 2008. However, the patch didn't make it into Emacs 23.1 nor does it appear in CVS Emacs as of yet. Your best bet for now might be to patch your version of server.el locally.