/src/wrappers/zmq/examples/zmq_example_server.e
Specman e | 48 lines | 40 code | 4 blank | 4 comment | 4 complexity | 4aab7c7a08c534f8bc58c5e3eda065b6 MD5 | raw file
1class ZMQ_EXAMPLE_SERVER 2 -- Port of the server of the simple example at http://www.zeromq.org/area:docs-v20 3insert 4 MULTIPROCESSING 5 ANY 6create {} make 7feature {ANY} 8 context: ZMQ_CONTEXT 9 socket: ZMQ_REP_SOCKET 10 request, answer: ZMQ_STRING_MESSAGE 11 12 make 13 local now: TIME; exc: ZMQ_EXCEPTION; my_pid: ABSTRACT_STRING; endpoint: STRING 14 do 15 my_pid := & process_id 16 create context 17 socket := context.new_rep_socket 18 -- Bind to the TCP transport and port 5555 on the 'lo' interface 19 -- endpoint := once "tcp://*:5555" 20 --socket.bind(endpoint) 21 socket.bind("tcp://*:5555") 22 23 if socket.is_successful then 24 now.update; 25 ("#(1): server online%N" # &now).print_on(std_output) 26 from until socket.is_unsuccessful loop -- i.e. "forever do" 27 ("#(1): server (pid #(2)) listening%N" # &now # my_pid).print_on(std_output) 28 create request 29 socket.wait_for(request) 30 now.update 31 if socket.is_successful then 32 ("#(1): server #(2) received request '#(3)'.%N" # &now # my_pid # request).print_on(std_output) 33 create answer.from_string(answer_template # my_pid) 34 now.update; 35 ("#(1): server #(2) answering '#(3)'.%N" # &now # my_pid # answer).print_on(std_output) 36 socket.send(answer) -- Send back our canned answer 37 else 38 exc := socket.zmq_exception; 39 ("#(1): unsuccessful receive '#(2)' (code #(3))%N" # &now # exc.description # & exc.error_code).print_on(std_output) 40 end 41 end 42 else ("#(1): unsuccessful bind '#(2)'%N" # &now # socket.zmq_exception.description).print_on(std_output) 43 end 44 end 45 46 answer_template: STRING "Greetings by server ##(1)." 47 48end -- class ZMQ_EXAMPLE_SERVER