fszmq


Multi-socket Poller

Reading from multiple sockets. This version uses a uses ZMQ's polling functionality.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
#r "fszmq.dll"
open fszmq
open System.Threading

let main () =
  use context = new Context ()

  // connect to task ventilator
  let receiver = Context.pull context
  Socket.connect receiver "tcp://localhost:5557"

  // connect to weather server
  let subscriber = Context.sub context
  Socket.connect subscriber "tcp://localhost:5556"
  Socket.subscribe subscriber [ "10001"B ]

  // process messages from both sockets
  while true do
    let items =
      [ receiver
        |> Polling.pollIn (fun s -> let msg = Socket.recv s
                                    ((* process task *)))
        subscriber
        |> Polling.pollIn (fun s -> let msg = Socket.recv s
                                    ((* process update *))) ]
    Polling.pollForever items |> ignore

  0 // return code
module docs
module PATH

from docs
val hijack : unit -> unit

Full name: docs.PATH.hijack
namespace fszmq
namespace System
namespace System.Threading
val main : unit -> int

Full name: Mspoller.main
val context : System.IDisposable
val receiver : obj
val subscriber : obj
val items : obj list
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
val release : unit -> unit

Full name: docs.PATH.release
Fork me on GitHub