框架

Socket.IO 快速参考

Socket.IO 快速参考 的可打印速查表,适合快速查阅、学习和桌边参考

来源
Socket.IO Documentation (socket.io/docs)
许可证
MIT
更新时间
2026-03-27

示例

速查表包含什么

  • 安装
  • 事件
  • 发送消息
  • 广播
  • 房间
  • 命名空间
  • 中间件
  • 错误处理
  • 确认回执
  • 常用模式

服务端安装(Node.js)

import { Server } from "socket.io";
const io = new Server(3000, {
  cors: { origin: "http://localhost:5173" }
});

客户端安装

import { io } from "socket.io-client";
const socket = io("http://localhost:3000");

与 Express 集成

import express from "express";
import { createServer } from "http";
import { Server } from "socket.io";
const app = express();
const server = createServer(app);
const io = new Server(server);

下载完整速查表,获取所有章节的打印排版版本

下载 PDF

下载

选择适合你阅读方式的版本