- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试按照 this tutorial 构建一个简单的客户端-服务器程序关于 Haskell 的网络管道库。
这是客户端,它同时向服务器发送文件并接收答案:
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent.Async (concurrently)
import Data.Functor (void)
import Conduit
import Data.Conduit.Network
main = runTCPClient (clientSettings 4000 "localhost") $ \server ->
void $ concurrently
(runConduitRes $ sourceFile "input.txt" .| appSink server)
(runConduit $ appSource server .| stdoutC)
这是服务器,它计算每个单词的出现次数并将结果发送回客户端:
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Char8 (pack)
import Data.Foldable (toList)
import Data.HashMap.Lazy (empty, insertWith)
import Data.Word8 (isAlphaNum)
import Conduit
import Data.Conduit.Network
import qualified Data.Conduit.Combinators as CC
main = runTCPServer (serverSettings 4000 "*") $ \appData -> do
hashMap <- runConduit $ appSource appData
.| CC.splitOnUnboundedE (not . isAlphaNum)
.| foldMC insertInHashMap empty
runConduit $ yield (pack $ show $ toList hashMap)
.| iterMC print
.| appSink appData
insertInHashMap x v = do
return (insertWith (+) v 1 x)
问题是,在我手动关闭客户端之前,服务器不会到达屈服阶段,因此永远不会回答它。我注意到,从客户端删除并发并仅保留将数据发送到服务器的部分,一切正常。
那么,如何在不破坏流程的情况下保留客户端的接收部分呢?
最佳答案
出现死锁:客户端在关闭连接之前等待服务器响应,但服务器不知道客户端已完成发送数据并正在等待更多数据。这基本上就是 https://cr.yp.to/tcpip/twofd.html 中描述的问题。 :
When the
generate-data
program finishes, the same fd is still open in theconsume-data
program, so the kernel has no idea that it should send a FIN.
就您而言,修复需要在客户端进行。您需要调用shutdown
与 ShutdownSend
一旦 conduit
完成通过套接字发送 input.txt 的内容,就在套接字上。
这是一种方法(我不确定是否有更好的方法):
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent.Async (concurrently)
import Data.Functor (void)
import Data.Foldable (traverse_)
import Conduit
import Data.Conduit.Network
import Data.Streaming.Network (appRawSocket)
import Network.Socket (shutdown, ShutdownCmd(..))
main = runTCPClient (clientSettings 4000 "localhost") $ \server ->
void $ concurrently
((runConduitRes $ sourceFile "input.txt" .| appSink server) >> doneWriting server)
(runConduit $ appSource server .| stdoutC)
doneWriting = traverse_ (`shutdown` ShutdownSend) . appRawSocket
旁注:在这种情况下,您实际上不需要客户端中的并发性,因为在完成向服务器的写入之前,永远不会从服务器读取任何内容。您可以在写入并关闭后进行读取。
关于Haskell 服务器不回复客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56177515/
我有多个 InOut 模式的顺序队列,每个队列通向一个 Camel 处理器。如果处理器花费太多时间进行处理,我希望请求-答复检测到超时并发送 ExchangeTimedOutException。Cam
我是一名学生,试图了解更多关于 C# 中的 ARP 和套接字的信息 为此,我尝试使用原始 Socket 发送 ARP 请求和回复。在 C# 中。 我已经在一个字节数组中手动重建了一个 ARP 回复
我正在使用 Amazon Web Services 数据库 dynamodb。它返回一个 JSON,看起来像这样: {"Responses":{"friends":[{"to_username":"u
我有 servlet,它创建 html 文件,然后将其转换为 pdf 文件: private void ConvertHTMLtoPDF(String sConvertationProgramm, S
我正在为我的项目使用 Mailkit 库 (Imap)。 我可以轻松地通过 SmtpClient 发送新消息。 目前我正在研究如何回复特定邮件。是否可以向该回复邮件添加更多收件人? @jstedfas
这个问题已经有答案了: How to parse JSON in Java (36 个回答) 已关闭 7 年前。 请您告诉我如何解析 JSON 回复。我从 https://api.privatbank
我正在尝试从事 YouTube 视频评级工作。但我被困在这里了。这两个 YouTube 评级请求有什么区别? https://www.googleapis.com/youtube/v3/videos/
我搜索了该网站,令人惊讶的是没有找到任何适合我情况的答案。所以我发布了这个问题。 我正在使用 jQuery AJAX 来获取网页并将其动态添加到网站。但我的代码不起作用并抛出错误 ERROR Type
我正在编写一个 C 程序来搜索本地网络上的 smb 共享并安装它们。为了获取找到的 smb 服务器的主机名,我向服务器发送了 udp nbns 数据包。数据包正确,服务器回复。我正在使用wiresha
我正在尝试使用 Java 创建自己的 WebSocket 服务器。 当我的客户端连接时,我收到以下请求: (14): GET / HTTP/1.1 (18): Upgrade: WebSocket (
我正在使用 Nodejs、Express、MySQL、EJS。 用户能够创建帖子和评论/回复评论/回复对这些帖子的回复。 问题:我不知道如何以允许我在 EJS 中呈现它们的方式将数据分类为对象/数组。
我正在用 .NET c++ 编写程序。我正在本地网络上发送广播 ping。我的所有目标设备都能够响应 ping 广播,事实上我在 Wireshark 中跟踪了它们的所有响应。我的目标是检索所有响应站点
我有一个向 JMS MDB 发送请求的客户端。它可以很好地向 MDB 发送消息,但我一辈子都无法弄清楚如何让客户端接收 MDB 发回给它的响应。 编辑:客户端代码是同一实例上的 Web 服务,使用 @
我使用钩子(Hook)函数制作了一个模块。它可以工作,但是当我使用 ping google.com 时,我得到 0045 作为 icmp 类型。但我认为它应该是 0 用于回显回复。我使用了以下打印命令
我正在用 C 从头开始编写一个网络库。我已经实现了以太网协议(protocol),现在我想让 ARP 工作。发送请求/回复工作正常,但接收工作不正常。当我发送一个发送请求并等待它之后的回复时,re
我在替换字符串的一部分时遇到问题。现在这段代码。我的目标是针对包含此字典中的键的每个字符串。 mapping = { "St": "Street", "St.": "Stree
我有一个 WCF p2p 网状网络,它运行良好,适合单向对话。我正在研究是否可以调用一种方法来添加两个数字并返回和总和。 但是我在尝试连接时遇到错误: 契约(Contract)需要请求/回复,但绑定(
大家好,我正在尝试使用分块编码流式传输多媒体数据。因此,我首先尝试使用分块编码发送文本数据。 这是我的代码。我创建了一个服务器套接字,我在上面监听请求(端口 80),回复请求,然后我的程序终止。无论您
我的 Servlet 中有一些图像,我想将它们下载到我的 Android 应用中。 我正在对这个 URL 执行一个 GET 请求: public static final String URL ="h
文档:https://developers.google.com/apps-script/reference/gmail/gmail-message#replybody-options 当跟进一封电子
我是一名优秀的程序员,十分优秀!