MyNixOS website logo
Description

Bindings to the nanomsg library.

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.

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
Metadata

Version

0.2.4

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows