Paste: zmq hello-world example

Author: Arrogant
Mode: factor
Date: Tue, 2 Nov 2010 06:59:26
Plain Text |
! hello world server
USING:
    kernel io io.encodings.utf8 destructors byte-arrays calendar
    zmq zmq.ffi
    alien.data
    threads
    ;
IN: zmq.examples.hello-world-server

: hello-world-server ( -- )
    1 <context>
    [
        ZMQ_REP "tcp://*:5555"
        [
            [ t ] [
                dup utf8 recv-string print yield
                1 seconds sleep
                [ "World" utf8 send-string ] keep
            ] while
            drop
        ] with-binding
    ] with-disposal
    ;

MAIN: hello-world-server

! hello world client

USING:
    kernel io io.encodings.utf8 destructors threads
    math.ranges formatting
    zmq zmq.ffi
    alien.data
    locals sequences arrays
    ;
IN: zmq.examples.hello-world-client

: hello-world-client ( -- )
    1 <context>
    [
        "Connecting to hello world server..." print
        ZMQ_REQ "tcp://localhost:5555"
        [
            10 [1,b]
            [| request |
                request "Sending request %d...\n" printf
                dup "Hello" utf8 send-string
                dup utf8 recv-string
                request swap "Received reply %d [ %s ]\n" printf
                yield
            ] each
            drop
        ] with-connection
    ] with-disposal
    ;

MAIN: hello-world-client

New Annotation

Summary:
Author:
Mode:
Body: