[Libwebsockets] using unix or tcp sockets?

Per Bothner per at bothner.com
Tue Aug 29 02:50:45 CEST 2017


I'm looking into integrating session management (as in GNU screen or tmux)
into DomTerm (http://domterm.org).  This seems to imply a separate "long-running"
server process that manages the various processes and ptys. Short-running clients
would send requests (such as "create a new session" or "list sessions") to the server.

It seems to make sense to use Unix domain sockets for communication between the
clients and the server, for at least two reasons:
(1) discoverability: the socket can be bound to a standard (per-user) place
in the file system
(2) security: by default the socket has the same ownership and permissions
as the user running the server, so a client belonging to one user can't
communicate with the server belonging to another user.

On the other hand, it's not clear to me how to mix unix and tcp sockets with libwebsockets,
and communicating between the server and the display front-ends
(which are web browsers, possibly embedded, like Electron, but not always)
would seem to require tcp sockets.

Using http over tcp sockets would make for a simpler server.
Discoverability can be handled by writing the listening port to a file
in the fire system, where the client can read it.  Security is harder,
but as long we're just working locally simple authentication may be
enough: The server can generate a key, write it to a user-only-readable file,
which the client can read and present to the server.

(Later, I want to figure out a good way to handle remote sessions,
where the client and front-end are on one machine, and the server
is on a different machine (and the connection between them might be insecure
or intermittent), as well as shared sessions (multiple users each with
their own front-ends sharing access to a single remote sessions).
It seems plausible to use ssh for this.  However, for now I just want to
get local sessions working simply, securely, and reliably.)

If we use http, I know how to write the server part, but I need to
figure out how to write the client.  It needs to package up a request
(based on the command line, and also env/pwd), create a GET, send it to
the server, and wait for a response.  Nothing fancy.  I can puzzle
my way through test-server/test-client.c, but it does an awful lot.
Do you have a simpler example?

Any advice otherwise?
-- 
	--Per Bothner
per at bothner.com   http://per.bothner.com/


More information about the Libwebsockets mailing list