小编Sij*_*Din的帖子

如何从客户端触发websocket帧碎片?

我正在构建一个 Web 套接字服务器,但是,出于测试目的,我希望 Chrome 或 Firefox 或任何其他浏览器发送分段消息,以便我可以测试我的实现。

我什至尝试过发送 100K 文本数据,FIN 标志始终设置为 1,操作码为 TEXT。

有没有办法手动触发碎片帧?有没有更灵活的客户?

websocket

7
推荐指数
1
解决办法
1828
查看次数

在JS中的<code>标记内用换句号替换换行符

我试图<code></code><br>s 替换标签内的所有新行,但我的正则表达式不起作用.这是输入文本:

<p>
   <span class="dingus">?</span> for linebreak add 2 spaces at end
</p>
<code class="hl">
    Text in a code pre element
    is displayed in a fixed-width
    font, and it preserves
    both      spaces and
    line breaks
</code>
<p class="ar">
    <a href="/editing-help" target="_edithelp">formatting help »</a><br>
    <a href="/questions/how-to-ask">asking help »</a>
</p>
Run Code Online (Sandbox Code Playgroud)

正则表达式:

var txt = str.replace(/<code[^>]*>((.|\n)*?)<\/code>/gm,function(match){
    return match.replace(/\n/gi, '<br>');
});
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我知道使用解析器是理想的解决方案,但仍然想知道上面的例子是否可以使用简单的正则表达式.

javascript regex replace

0
推荐指数
1
解决办法
124
查看次数

标签 统计

javascript ×1

regex ×1

replace ×1

websocket ×1