Error while building our own streaming server

Hi i am currently trying to create our own streaming server as provided in the tutorial below.

https://docs.techsoft3d.com/communicator/latest/build/tutorials/building-streaming-service/setup.html

I have passes the absolute path to paths.js directory
licenseFile: “xxxxxxxxx”,
executablePath: “E:/Received/HOOPS_Communicator_2020_SP1_Windows/HOOPS_Communicator_2020_SP1/server/bin/win64/ts3d_sc_server.exe”,

modelDirectory: “E:/Received/HOOPS_Communicator_2020_SP1_Windows/HOOPS_Communicator_2020_SP1/tutorials/server_tutorial/models/helloworld.scz”
};

engine-wasm.js:428 WebSocket connection to ‘ws://localhost:9999/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

what coukd possibly be the problem…
thanks in advance for any help .

Hi @ys878645, can you please show me the full command you used to launch the ts3d_sc_server.exe? The error makes me think that the stream cache server is not running, or it’s not running on the port you tried to connect to (9999).

Thanks and sorry for the delay in response here.

its say spawn id exited with code 0.

this is the link i am following - Introduction
Here is the code

const { spawn } = require(‘child_process’);

const { v4: uuidv4 } = require(‘uuid’);

const express = require(‘express’);

class ServerInfo {

constructor(serverId, wsPort, rendererType, response) {

this.serverId = serverId;

this.wsPort = wsPort;

this.response = response;

this.rendererType = rendererType;

this.lastPingTime = null;

this.startTime = new Date();

}

}

class streamCacheServer {

constructor(licenseFile, executablePath, modelDirectory, expressApp) {

this.licenseFile = licenseFile;

this.executablePath = executablePath;

this.modelDirectory = modelDirectory;

this.expressApp = expressApp;

this.serverPort = null;

this.wsBasePort = 55000;

this.serverInfo = null;

this.availableWsPorts = [];

this.activeSpawns = new Map();

}

start(port) {

this.serverPort = port;

this.expressApp.use(express.json());

this.expressApp.use(function (req, res, next) {

  res.header("Access-Control-Allow-Origin", "*");

  res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS");

  res.header("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers");

  next();

});

this.expressApp.post("/loadModel", this.startViewer.bind(this));

this.expressApp.post("/liveliness/:serverId", this.liveliness.bind(this));

this.expressApp.listen(this.serverPort);

}

startViewer(req, res) {

let rendererType = "csr";

const requestJson = req.body;

if ("rendererType" in requestJson) {

  rendererType = requestJson.rendererType;

}

const serverId = uuidv4();

const wsPort =  this.availableWsPorts.length ? this.availableWsPorts.pop() : this.wsBasePort++;

this.serverInfo = new ServerInfo(serverId, wsPort, rendererType, res);

this.activeSpawns.set(serverId, this.serverInfo);

let args = [

  "--id", this.serverInfo.serverId,

  "--sc-port", this.serverInfo.wsPort,

  '--liveliness-endpoint', `http://localhost:${this.serverPort}/liveliness`,

  "--model-search-directories", this.modelDirectory,

  "--license-file", this.licenseFile

];

if (this.serverInfo.rendererType == "ssr") {

  args.push("--ssr", "true");

}

const serverOptions = { env: { "DISPLAY": ":0" } };

let process = spawn(this.executablePath, args, serverOptions);

process.on("exit", (code) => {

  console.log(`spawn ${this.serverInfo.serverId} exited with code: ${code}`);

});

res.status(200).json({result: `spawned viewer on websocket port: ${this.serverInfo.wsPort}`});

}

liveliness(req, res) {

const serverId = req.params.serverId;

if (!this.serverInfo) {

  console.log(`unknown id: ${serverId}`);

  res.status(404).json({ error: "invalid serverId." });

  return;

}

const updateType = req.query.liveliness;

switch (updateType) {

  case "ready":

    console.log(`liveliness ready: ${this.serverInfo.serverId}`);

    this.serverInfo.response.status(201).json({

      directory: this.modelDirectory,

      id: this.serverInfo.serverId,

      endpoint: `ws://localhost:${this.serverInfo.wsPort}`,

      rendererType: this.serverInfo.rendererType

    });

    this.serverInfo.response = null;

    break;

  case "disconnect":

    console.log(`liveliness disconnect: ${this.serverInfo.serverId}`);

    this.availableWsPorts.push(this.serverInfo.wsPort);

    this.activeSpawns.delete(this.serverInfo.spawnId);

    res.status(200).end();

    break;

  case "ping":

    this.serverInfo.lastPingTime = new Date();

    res.status(200).end();

    break;

  default:

    res.status(400).json({ error: "invalid liveliness value" });

}

}

}

module.exports = { streamCacheServer }