[Haskell-cafe] How to design an network client with user program.

Alexander V Vershilov alexander.vershilov at gmail.com
Wed Apr 10 13:08:43 CEST 2013


On 10 April 2013 14:56, Michael Snoyman <michael at snoyman.com> wrote:

> It doesn't seem like you're trying to perform multiple actions
> simultaneously. For example, you don't need to be able to read from the
> server and send data back at the same time. Instead, you'll have a single
> thread of execution. Am I right?
>

Not  exaclty, user code is not only SeverMessage driven but can generate
messages and works on it's own (time-events, or some external events).
For example user code may generate random messages even there is no message
from server, (i.e. wait for some
timeout and then feed sender with message), or do some long running events,
(e.g. wait for 5 minutes), in both
of those cases one threaded pipeline is broken.

If so, it seems like the simplest thing would be for you to allow users to
> write something like:
>
>     Conduit MsgFromServer m MsgToServer
>
> Assuming you had conduits to convert an incoming byte stream to a stream
> of MsgFromServer and the equivalent for sending, you'd end up with
> something like:
>
>     appSource appData $$ toMsgFromServer =$ clientSuppliedConduit =$
> fromMsgToServer =$ appSink appData
>
> Michael
>
>
> On Tue, Apr 9, 2013 at 1:09 PM, Alexander V Vershilov <
> alexander.vershilov at gmail.com> wrote:
>
>>
>> Hello.
>>
>> I have next problem: I have a network client that connects to server,
>> listens for messages and generate responces. So the control flow can be
>> represended as:
>>
>> server -- input -> {generate output} -> output
>>
>> Output can be generated using default implementation or can overriden by
>> user.
>>
>> The main difficulty appeares when I need to add a user program on the top
>> of this logic,
>> i.e. from user-side I want to have dsl:smth like
>>
>> withClient $ do
>>    x <- send message
>>    waitFor x
>>    timeout 5000000
>>    forever $ sendRandomMessage
>>
>> i.e. an ability to send messages, waiting for some event (message to
>> come), waiting for
>> timeout.
>>
>> The question is how to define such logic without a big overhead. I see a
>> solution using conduit, it's possible to create 3 processes: listener,
>> user, sender.
>>
>>                          +----> user ----+
>>                          |                    |
>> -input -> listener +----------------->+---- sender ->
>>
>> and use TQueue or TChan to send messages between them, however there can
>> be another possible solutions, that uses less resources, or another design.
>>
>>
>> --
>> Alexander
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>


-- 
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130410/45d67b7e/attachment.htm>


More information about the Haskell-Cafe mailing list