MCPcopy
hub / github.com/socketio/socket.io / initServer

Function initServer

examples/cluster-engine-redis/server.js:10–39  ·  examples/cluster-engine-redis/server.js::initServer
(port)

Source from the content-addressed store, hash-verified

8const { createProxyServer } = proxyModule;
9
10async function initServer(port) {
11 const httpServer = createServer((req, res) => {
12 res.writeHead(404).end();
13 });
14
15 const pubClient = createClient();
16 const subClient = pubClient.duplicate();
17
18 await Promise.all([pubClient.connect(), subClient.connect()]);
19
20 const engine = new RedisEngine(pubClient, subClient);
21
22 engine.attach(httpServer, {
23 path: class="st">"/socket.io/",
24 });
25
26 const io = new Server({
27 adapter: createAdapter(pubClient, subClient),
28 });
29
30 io.bind(engine);
31
32 io.on(class="st">"connection", (socket) => {
33 socket.on(class="st">"hello", () => {
34 socket.broadcast.emit(class="st">"hello", socket.id, port);
35 });
36 });
37
38 httpServer.listen(port);
39}
40
41function initProxy() {
42 const proxy = createProxyServer();

Callers 1

server.jsFile · 0.70

Calls 11

bindMethod · 0.95
createServerFunction · 0.85
createClientFunction · 0.85
createAdapterFunction · 0.85
listenMethod · 0.80
emitMethod · 0.65
endMethod · 0.45
writeHeadMethod · 0.45
connectMethod · 0.45
attachMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected