Unix domain socket

Is there a way to run Theia on a Unix domain socket, as opposed to TCP/IP? If the answer is no, can someone point to the right direction in the code base – which needs to be modified?

best wishes:
steven

Hi @steven-varga, are you talking about using an IPC socket for a Theia electron application? Because I don’t really see a use case for IPC in a browser environment.

Either way, as far as I know, Theia is using already IPC once it is packaged as an electron app. See the IPCConnectionProvider for more info.

@msujew Thank you for the response! In web environment IPC or Unix Domain Sockets may be used in combination with an existing web proxy.

I am expecting a code snippet somewhere some place similar to:

var server = net.createServer(function(client) {
    ...
});
server.listen(3000);

which can be modified to:

var net = require('net');
var server = net.createServer(function(client) {
    ...
});
server.listen('/var/run/theia.sock');

I would like something similar to the following line:

yarn theia start /my-workspace --socket /var/run/theia.sock

Do you happened to know how to achieve this?

UPDATE:
I figured it out, for the record I attached diff. It is not production quality but a good start. The code snippet needs some work such as removal of the socket, permissions etc… I am not sure if there is any interest, if so I can send a PR.

diff --git a/packages/core/src/node/backend-application.ts b/packages/core/src/node/backend-application.ts
index 8e50774a19..072ce6a31b 100644
--- a/packages/core/src/node/backend-application.ts
+++ b/packages/core/src/node/backend-application.ts
@@ -101,8 +101,9 @@ export interface BackendApplicationContribution {
 @injectable()
 export class BackendApplicationCliContribution implements CliContribution {
 
-    port: number;
+    port: number | undefined;
     hostname: string | undefined;
+    socket: string | undefined;
     ssl: boolean | undefined;
     cert: string | undefined;
     certkey: string | undefined;
@@ -111,6 +112,7 @@ export class BackendApplicationCliContribution implements CliContribution {
     configure(conf: yargs.Argv): void {
         conf.option('port', { alias: 'p', description: 'The port the backend server listens on.', type: 'number', default: DEFAULT_PORT });
         conf.option('hostname', { alias: 'h', description: 'The allowed hostname for connections.', type: 'string', default: DEFAULT_HOST });
+        conf.option('socket', { alias: 's', description: 'path of unix domain socket', type: 'string' });
         conf.option('ssl', { description: 'Use SSL (HTTPS), cert and certkey must also be set', type: 'boolean', default: DEFAULT_SSL });
         conf.option('cert', { description: 'Path to SSL certificate.', type: 'string' });
         conf.option('certkey', { description: 'Path to SSL certificate key.', type: 'string' });
@@ -120,6 +122,7 @@ export class BackendApplicationCliContribution implements CliContribution {
     setArguments(args: yargs.Arguments): void {
         this.port = args.port as number;
         this.hostname = args.hostname as string;
+        this.socket = args.socket as string;
         this.ssl = args.ssl as boolean;
         this.cert = args.cert as string;
         this.certkey = args.certkey as string;
@@ -248,6 +251,7 @@ export class BackendApplication {
     async start(aPort?: number, aHostname?: string): Promise<http.Server | https.Server> {
         const hostname = aHostname !== undefined ? aHostname : this.cliParams.hostname;
         const port = aPort !== undefined ? aPort : this.cliParams.port;
+        const socket = this.cliParams.socket
 
         const deferred = new Deferred<http.Server | https.Server>();
         let server: http.Server | https.Server;
@@ -289,11 +293,16 @@ export class BackendApplication {
             setTimeout(process.exit, 0, 1);
         });
 
-        server.listen(port, hostname, () => {
-            const scheme = this.cliParams.ssl ? 'https' : 'http';
-            console.info(`Theia app listening on ${scheme}://${hostname || 'localhost'}:${(server.address() as AddressInfo).port}.`);
-            deferred.resolve(server);
-        });
+        if (socket) {
+            console.info(`Theia app listening on unix:${socket}`);
+            server.listen(this.cliParams.socket)
+        } else {
+            server.listen(port, hostname, () => {
+                const scheme = this.cliParams.ssl ? 'https' : 'http';
+                console.info(`Theia app listening on ${scheme}://${hostname || 'localhost'}:${(server.address() as AddressInfo).port}.`);
+                deferred.resolve(server);
+            });
+        }
 
         /* Allow any number of websocket servers.  */
         server.setMaxListeners(0);