/src/wrappers/zmq/examples/zmq_example_server.e

http://github.com/tybor/Liberty · Specman e · 48 lines · 40 code · 4 blank · 4 comment · 4 complexity · 4aab7c7a08c534f8bc58c5e3eda065b6 MD5 · raw file

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