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

推荐订阅源

GbyAI
GbyAI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
Netflix TechBlog - Medium
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
F
Full Disclosure
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
NISL@THU
NISL@THU
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
Latest news
Latest news
C
CERT Recently Published Vulnerability Notes
P
Privacy & Cybersecurity Law Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
Tor Project blog
A
About on SuperTechFans
博客园 - 司徒正美
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LINUX DO - 热门话题
Know Your Adversary
Know Your Adversary
T
Tenable Blog
K
Kaspersky official blog
Simon Willison's Weblog
Simon Willison's Weblog
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
Cisco Talos Blog
Cisco Talos Blog
U
Unit 42
T
The Blog of Author Tim Ferriss
T
Threatpost
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
P
Palo Alto Networks Blog

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