9.3 并发连接管理

连接映射

1
2
3
4
5
6
7
8
9
10
const connections = new Map<string, ConnectionInfo>();

wss.on('connection', (ws, req) => {
const connectionId = generateId();
connections.set(connectionId, { id: connectionId, ws });

// 为每个连接创建独立的 Agent
const agent = new Agent(config);
agents.set(connectionId, agent);
});

导航

上一篇: 9.2 WebSocket 通信

下一篇: 9.4 协议设计