Connect to Swank via SSH

A useful technique for remote controlling lisp applications is to use the ability of SLIME to connect to a Swank server over the network. A Swank server can be started, for example, by loading "swank" via quicklisp and calling:

(swank:create-server)

Useful keyword arguments of swank:create-server are :port (listens on a different port than 4005) and :dont-close, which makes Swank listen for subsequent connections after disconnecting.

To connect from SLIME use M-x slime-connect and enter the address and port of the swank server. When you are done, disconnect with M-x slime-disconnect.

If you set up a remote Swank server, don’t to open a port in the remote firewall. Instead, use a closed port and an SSH tunnel instead. This connects the local port 4006 with the port 12345 on the remote machine:

$ ssh -L 4006:localhost:12345 -N remote-host

-L creates the tunnel, -N tells SSH that no actual shell access is needed. Now you can connect to a remote Swank listening on port 12345 by telling slime-connect to connect to localhost:4006.

Summary

Remote:

(swank:create-server :port 12345 :dont-close t)

Local:

ssh -L 4006:localhost:12345 -N remote-host

M-x slime-connect RET localhost/127.0.0.1 RET 4006 RET

M-x slime-disconnect RET


Want to comment on this article? Write me an email (GPG key: 0x12B9620D).