### Install SocketCluster Server Source: https://github.com/socketcluster/socketcluster-server/blob/master/README.md Installs the socketcluster-server package using npm. This is a prerequisite for using the SocketCluster server module. ```bash npm install socketcluster-server ``` -------------------------------- ### Basic Server Setup and Connection Handling Source: https://github.com/socketcluster/socketcluster-server/blob/master/README.md Demonstrates how to attach the SocketCluster server to a Node.js HTTP server and handle new inbound socket connections. It includes examples for responding to remote procedure calls (RPCs) and receiving transmitted events. ```javascript const http = require('http'); const socketClusterServer = require('socketcluster-server'); let httpServer = http.createServer(); let agServer = socketClusterServer.attach(httpServer); (async () => { // Handle new inbound sockets. for await (let {socket} of agServer.listener('connection')) { (async () => { // Set up a loop to handle and respond to RPCs for a procedure. for await (let req of socket.procedure('customProc')) { if (req.data.bad) { let error = new Error('Server failed to execute the procedure'); error.name = 'BadCustomError'; req.error(error); } else { req.end('Success'); } } })(); (async () => { // Set up a loop to handle remote transmitted events. for await (let data of socket.receiver('customRemoteEvent')) { // ... } })(); } })(); httpServer.listen(8000); ``` -------------------------------- ### Compatibility Mode Configuration Source: https://github.com/socketcluster/socketcluster-server/blob/master/README.md Configures the SocketCluster server for compatibility with older SocketCluster clients by setting the protocol version and the server path. ```javascript let agServer = socketClusterServer.attach(httpServer, { protocolVersion: 1, path: '/socketcluster/' }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.