fszmq


Multi-socket Reader

Reading from multiple sockets. This version uses a simple recv loop.

 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: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
#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 ]

  let rec getTask () =
    match Socket.tryRecv receiver 255 ZMQ.DONTWAIT with
    | Some msg  ->  (* process task *)
                    getTask ()
    | None      ->  ((* BREAK *))

  let rec getUpdate () =
    match Socket.tryRecv receiver 255 ZMQ.DONTWAIT with
    | Some msg  ->  (* process update *)
                    getUpdate ()
    | None      ->  ((* BREAK *))

  // process messages from both sockets
  // we prioritize traffic from the task ventilator
  while true do
    getTask ()
    getUpdate ()
    // no activity, so sleep for 1 msec
    Thread.Sleep 1

  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: Msreader.main
val context : System.IDisposable
val receiver : obj
val subscriber : obj
val getTask : (unit -> unit)
union case Option.Some: Value: 'T -> Option<'T>
val msg : obj
union case Option.None: Option<'T>
val getUpdate : (unit -> unit)
Multiple items
type Thread =
  inherit CriticalFinalizerObject
  new : start:ThreadStart -> Thread + 3 overloads
  member Abort : unit -> unit + 1 overload
  member ApartmentState : ApartmentState with get, set
  member CurrentCulture : CultureInfo with get, set
  member CurrentUICulture : CultureInfo with get, set
  member DisableComObjectEagerCleanup : unit -> unit
  member ExecutionContext : ExecutionContext
  member GetApartmentState : unit -> ApartmentState
  member GetCompressedStack : unit -> CompressedStack
  member GetHashCode : unit -> int
  ...

Full name: System.Threading.Thread

--------------------
Thread(start: ThreadStart) : unit
Thread(start: ParameterizedThreadStart) : unit
Thread(start: ThreadStart, maxStackSize: int) : unit
Thread(start: ParameterizedThreadStart, maxStackSize: int) : unit
Thread.Sleep(timeout: System.TimeSpan) : unit
Thread.Sleep(millisecondsTimeout: int) : unit
val release : unit -> unit

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