Number of active runs of a repl

how do i figure out how many people are currently running my repl?
is there some kind of environment variable for this?

1 Like

I think you need to use GraphQL for this.

1 Like

graph what? where do i use this?

1 Like

GraphQL is the Replit API. Anybody who knows how to use it is forbidden to tell others how to use it, with the exception of these few templates. I’m not sure if I’m allowed to tell you where to look for other GQL queries so I’ll leave it at that. Sorry I can’t be of more assistance.

See also this recent post concerning GQL made by a Replit mod (now intern):

1 Like

it’s not possible whatsoever to see the amount of people actively running your repl. GraphQL has no such queries, and afaik, crosis has no channel access for cover page since it’s a temp shadow fork

3 Likes

You could use an analytics library or even just Socket.io and see how many people are connected if your making a website :slight_smile:

If your building a terminal program it’s a similar concept, just send a request to a different website that tracks how many people have the Repl open (e.g. once someone opens your Repl, send a initial request to the webserver and then each ten seconds send another followup request to confirm the Repl is open. Once you stop recieving requests the Repl can be considered closed)

No GraphQL needed @OmegaOrbitals @CoderElijah @bigminiboss –.–

4 Likes

bruh, I meant native sol but yes that’ll work, however, there’s no way to cleanly ensure in terminal repls that the user actually will reach the end of the prog since they can just press ctrl c and it’ll never get execed

1 Like

Thank you. I was just answering what GQL was and how to use (or not use) it since betatester1024 asked.

4 Likes

It’d probably be more efficient to open a websocket and use that.

3 Likes

oh lol I didn’t read I thought he meant a duel req one at the end and one in beginning, that’ll work but it’ll overload server really quickly

2 Likes

probably a good idea

1 Like

Ahem ahem I wonder who might have mentioned that xD

3 Likes

haha yeah, srry I shouldn’t have only thought of native, I was only thinking if replit stored it :man_facepalming:

1 Like

Would connecting to a random TCP server and leaving a socket open work? (That’d probably save egress)

2 Likes

I’m pretty sure it would since replit would close the socket after run stops

2 Likes

Probably, I’m just suggesting easy to implement ideas but if the user would want to implement that it works too :slight_smile:

2 Likes

I might actually test using a TCP socket now :slight_smile:

3 Likes

yeah afaik you just code a simple server that stores an active count on connect and subtracts on disconnect

2 Likes

Here’s a basic implementation of a TCP server for this (the server won’t be affected by egress limits, so it doesn’t have to be careful about sending data):

const net=require("net");
var sockets=0;
const srv=net.createServer(function(socket) {
  console.log(`Connection from ${socket.remoteAddress}:${socket.remotePort}`);
  if(!socket) return;
  sockets++;
  socket.write("HTTP/1.1 200 OK\r\n\r\n"+String(sockets));
  socket.addListener("data", function() {
    // Non-HTTP clients won't send data, end the socket!
    socket.end();
  })
  socket.addListener("close", function() {
    sockets--;
  });
});
srv.listen(11759, "0.0.0.0");

I set up an instance at shell.oddprotocol.org:11759 as an example.

3 Likes