GitXplorerGitXplorer
b

nanomsg-haskell

public
25 stars
12 forks
6 issues

Commits

List of commits on branch master.
Unverified
9228901f4fee23315c194d12004ea1e80df8fbea

Add Github Actions support

aadinapoli committed 5 months ago
Unverified
926f44d65408f4af5d5943cbfe6414b41ee9992d

drop test-frameworkfor tasty-discover

aadinapoli committed 5 months ago
Unverified
e97e7ab9558c7da4342523cb1cf41ca98144906f

Relax constraint on bytestring

aadinapoli committed 5 months ago
Unverified
23c5c207ae201439d4bd82f1510f3f27fbcd085a

Add cabal.project

aadinapoli committed 5 months ago
Unverified
a532268191bf75f0ad40cb0fe2b3a82e05b9a429

Shift maintainership to Ben

bbgamari committed 6 years ago
Unverified
1aef0069adb31441fd5bb371782888f0418cf0aa

Minor release 0.2.4

committed 6 years ago

README

The README file for this repository.

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