惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

Linux – 网上冲浪指南

手动升级一下 OpenWRT 如何安全地面向公网提供本地 NAS 上的 Web 服务 迁移博客到 VPS 解决 Qsirch 无法搜索文件夹的问题 N100 小主机遭遇 NVMe 硬盘故障:一次系统的诊断与反思 外接显示器 EDID 损坏如何处理 How to switch GitHub CLI account automatically 似乎修复了唤醒后键盘短暂失效的问题 性能与公平:解决 Linux 桌面无响应的取舍之道
How to simulate hard disconnection for websocket
Zeeko · 2025-10-15 · via Linux – 网上冲浪指南

虽然 Chrome/Firefox 在开发者工具中提供了离线模式,但是这个功能无法中断已经跟服务端建立起来的 WebSocket 连接。

如果你跟我一样使用 Linux 系统,那么就可以借助 iptables 命令来模拟连接中断的情况:

# 中断所有访问 localhost:3001 的连接
sudo iptables -I INPUT 1 -p tcp -i lo --dport 3001 -j DROP

# 恢复连接
sudo iptables -D INPUT -p tcp -i lo --dport 3001 -j DROP

如果你发现上面的命令不生效,那么可能是因为你的浏览器在通过 IPv6 地址访问本地端口,你需要将 iptables 替换成 ip6tables

如果你是基于 iptables 实现的 ufw 用户,你会发现 ufw 中建立的本地端口规则完全不生效,这是因为 ufw 不会处理任何从本机访问本机的连接,我们只能手动调用更底层的 iptables