how do i figure out how many people are currently running my repl?
is there some kind of environment variable for this?
I think you need to use GraphQL for this.
graph what? where do i use this?
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):
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
You could use an analytics library or even just Socket.io and see how many people are connected if your making a website
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 –.–
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
Thank you. I was just answering what GQL was and how to use (or not use) it since betatester1024 asked.
It’d probably be more efficient to open a websocket and use that.
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
probably a good idea
Ahem ahem I wonder who might have mentioned that xD
haha yeah, srry I shouldn’t have only thought of native, I was only thinking if replit stored it
Would connecting to a random TCP server and leaving a socket open work? (That’d probably save egress)
I’m pretty sure it would since replit would close the socket after run stops
Probably, I’m just suggesting easy to implement ideas but if the user would want to implement that it works too
I might actually test using a TCP socket now
yeah afaik you just code a simple server that stores an active count on connect and subtracts on disconnect
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.