udp-streaming: Streaming to and from UDP socket

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Simple fire-and-forget udp Streaming components modelled after udp-conduit


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.1, 0.2.0.0
Change log None available
Dependencies base (>=4.6 && <5.0), bytestring (>=0.10 && <0.11), network (>=2.0 && <3), resourcet (>=1.2 && <2), streaming (>=0.2 && <0.3) [details]
License MIT
Copyright (c) 2018 Mihai Giurgeanu
Author Mihai Giurgeanu
Maintainer mihai.giurgeanu@gmail.com
Category Network, Streaming
Home page https://hub.darcs.net/mihaigiurgeanu/udp-streaming
Uploaded by mihaigiurgeanu at 2018-03-17T18:22:16Z

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for udp-streaming-0.1.0.1

[back to package description]

udp-streaming

Simple fire and forget style streaming source and consumer in the spirit of the udp-conduit package.

Here's an example run in ghci that sends a message to UDP port 8888 on localhost:

>>> import qualified Streaming.Prelude as S
>>> import Streaming.UDP
>>> import Data.ByteString (ByteString)
>>> import Control.Monad.Trans.Resource
>>>
>>> :set -XOverloadedStrings
>>>
>>>
>>> runResourceT $ toSocket "127.0.0.1" 8888 $ S.yield ("hello world!\n" :: ByteString)

Here's an example in ghci where we continuously receive messages with a maximum length of 500 bytes on port 8888 on localhost:

>>> import qualified Streaming.Prelude as S
>>> import Streaming.UDP
>>> import Control.Monad.Trans.Resource
>>> import qualified Data.ByteString as B 
>>>
>>>
>>> runResourceT $ S.stdoutLn $ S.map (map (toEnum.fromEnum) . B.unpack) $ S.map fst $ fromUDP "127.0.0.1" 8888 500

Now, here's an example where we receive messages on port 8001, encode them as hex digits (using base16-bytestring package), and then send them on to port 8002.

>>> import qualified Streaming.Prelude as S
>>> import Streaming.UDP
>>> import Data.ByteString.Base16 (encode)
>>> import Control.Monad.Trans.Resource
>>>
>>>
>>> runResourceT $ toUDP "127.0.0.1" 8002 $ S.map encode $ S.map fst $ fromUDP "127.0.0.1" 8001 500

Or you could, in the previous example, to also log the messages receved, before processing and send them further:

>>> runResourceT $ toUDP "127.0.0.1" 8002 $ S.map encode $ S.map fst $ S.print $ S.copy $ fromUDP "127.0.0.1" 8001 500