Usage stats - Total connections #371
Answered
by
enisdenjo
bristoljon
asked this question in
Q&A
-
StoryAs a developer/sysadmin I want to know the total number of connected clients So that I can establish load capacity of a single server Acceptance criteria
|
Beta Was this translation helpful? Give feedback.
Answered by
enisdenjo
Jun 17, 2022
Replies: 1 comment
-
Quite easy, simply use the import { WebSocketServer } from 'ws';
import { useServer } from 'graphql-ws/lib/use/ws';
const server = new WebSocketServer({
port: 4000,
path: '/graphql',
});
let connectedClients = 0;
useServer(
{
// ...
onConnect: () => {
connectedClients++;
},
onClose: () => {
connectedClients--;
},
},
server,
);
console.log('Listening to port 4000'); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
enisdenjo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quite easy, simply use the
onConnect
andonClose
hooks: