-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accumulate ByteStrings into single result #488
Comments
I found that I can do the following: -- Client.hs
module Client where
main = do
let settings = clientSettings 80 "127.0.0.1"
result <- runTCPClient settings $ \appData -> do
runConduit $ yield "request" .| appSink appData
lazy <- runConduit $ appSource appData .| mapC Builder.byteString .| sinkLazyBuilder
return $ toStrict lazy
print result Now I get a single value from |
In order to make a system like this work, you need to do something like:
|
What I ended up doing is the following: -- Server.hs
module Server where
main = do
let settings = serverSettings 80 "127.0.0.1"
runTCPServer settings $ \appData -> do
void $
runConduitRes $
appSource appData .| handler .| appSink appData
handler :: Monad m => ConduitT ByteString ByteString m ()
handler = whenJustM await (const $ yield veryLongString)
-- Client.hs
module Client where
main = do
let settings = clientSettings 80 "127.0.0.1"
result <- runTCPClient settings $ \appData -> do
runConduit $ yield "request" .| appSink appData
runConduit $ appSource appData .| foldC
print result With this, the server will get only the first message with |
I have the following scenario: I have a server that on any response returns a ByteString which can be very long. On the client side, every now and then I perform a request to the server and I expect to get the full ByteString. The code is as follows:
Now, if I replace
???
withheadC
, as long as the ByteString that the server sends is not too long everything works just fine, but if it happens to be long enough I only get part of it.Ideally I would accumulate all ByteStrings until the server stops sending them. In other issues it's mentioned that I should use
Builder
s for this task, but I'm not quite sure how to get that working, so I would appreciate any suggestions.The text was updated successfully, but these errors were encountered: