nanomsg-haskell: Bindings to the nanomsg library

[ library, mit, network ] [ Propose Tags ] [ Report a vulnerability ]

This is a Haskell binding for the nanomsg library: http://nanomsg.org/.

There's support for (evented) blocking send and recv, a non-blocking receive, and for all the socket types and the functions you need to wire them up and tear them down again.

Most sockets options are available through accessor and mutator functions. Sockets are typed, transports are not.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.2.1.1, 0.2.2, 0.2.3, 0.2.4
Change log changelog
Dependencies base (>=4.5 && <5), binary (>=0.7 && <0.9), bytestring (>=0.9.0 && <0.11) [details]
Tested with ghc ==7.10.2
License MIT
Copyright Copyright (c) 2013 the nanomsg-haskell authors
Author Ivar Nymoen
Maintainer Ben Gamari <ben@smart-cactus.org>
Revised Revision 1 made by BenGamari at 2019-01-17T22:30:57Z
Category Network
Home page https://github.com/ivarnymoen/nanomsg-haskell
Source repo head: git clone https://github.com/ivarnymoen/nanomsg-haskell
Uploaded by IvarNymoen at 2019-01-16T08:02:57Z
Distributions
Reverse Dependencies 3 direct, 0 indirect [details]
Downloads 6131 total (21 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user [build log]
All reported builds failed as of 2019-01-16 [all 1 reports]

Readme for nanomsg-haskell-0.2.4

[back to package description]

nanomsg-haskell

This is a Haskell binding for the nanomsg library: http://nanomsg.org/.

There's support for (evented) blocking send and recv, a non-blocking receive, and for all the socket types and the functions you need to wire them up and tear them down again.

Most socket options are available through accessor and mutator functions. Sockets are typed, transports are not.

Building

You would normally make sure the nanomsg library is on your system and then install from Hackage, but can build from source following these steps:

  1. Build and install nanomsg (and zeromq, if you are building benchmarks)
  2. git clone https://github.com/ivarnymoen/nanomsg-haskell
  3. cd nanomsg-haskell && cabal sandbox init
  4. cabal install --dependencies-only [--enable-tests] [--enable-benchmarks]
  5. cabal configure [--enable-tests] [--enable-benchmarks]
  6. cabal build
  7. [cabal test]

Usage

Simple pub/sub example:

Server:

module Main where

import Nanomsg
import qualified Data.ByteString.Char8 as C
import Control.Monad (mapM_)
import Control.Concurrent (threadDelay)

main :: IO ()
main =
    withSocket Pub $ \s -> do
        _ <- bind s "tcp://*:5560"
        mapM_ (\num -> sendNumber s num) (cycle [1..1000000 :: Int])
    where
        sendNumber s number = do
            threadDelay 1000        -- let's conserve some cycles
            let numAsString = show number
            send s (C.pack numAsString)

Client:

module Main where

import Nanomsg
import qualified Data.ByteString.Char8 as C
import Control.Monad (forever)

main :: IO ()
main =
    withSocket Sub $ \s -> do
        _ <- connect s "tcp://localhost:5560"
        subscribe s $ C.pack ""
        forever $ do
            msg <- recv s
            C.putStrLn msg

Nonblocking client:

module Main where

import Nanomsg
import qualified Data.ByteString.Char8 as C
import Control.Monad (forever)
import Control.Concurrent (threadDelay)

main :: IO ()
main =
    withSocket Sub $ \s -> do
        _ <- connect s "tcp://localhost:5560"
        subscribe s $ C.pack ""
        forever $ do
            threadDelay 700           -- let's conserve some cycles
            msg <- recv' s
            C.putStrLn $ case msg of
                Nothing -> C.pack "No message"
                Just m  -> m