/src/wrappers/zmq/examples/zmq_example_client.e

http://github.com/tybor/Liberty · Specman e · 41 lines · 36 code · 3 blank · 2 comment · 5 complexity · aac80aa59144ce5134e7b394d765714c MD5 · raw file

  1. class ZMQ_EXAMPLE_CLIENT
  2. insert
  3. MULTIPROCESSING
  4. ANY
  5. create {ANY} make
  6. feature {ANY}
  7. context: ZMQ_CONTEXT
  8. socket: ZMQ_REQ_SOCKET
  9. message, answer: ZMQ_STRING_MESSAGE
  10. make
  11. local now: TIME; exc: ZMQ_EXCEPTION; my_pid: ABSTRACT_STRING
  12. do
  13. my_pid := & process_id
  14. create context -- Initialise 0MQ context
  15. socket := context.new_req_socket -- to send requests and receive replies
  16. -- Connect it to port 5555 on localhost using the TCP transport
  17. socket.connect ("tcp://localhost:5555")
  18. from until socket.is_unsuccessful loop -- forever
  19. -- Construct an example message with our query
  20. create message.from_string("Starting clint process #" + my_pid)
  21. socket.send(message)
  22. now.update;
  23. if socket.is_successful then -- Receive and display the result
  24. ("#(1) client #(2): message sent, waiting for reply%N" # &now # my_pid).print_on(std_output);
  25. create answer
  26. socket.wait_for(answer)
  27. if socket.is_successful then ("#(1) client #(2): received answer '#(3)'.%N" # &now # my_pid # answer).print_on(std_output)
  28. else
  29. exc := socket.zmq_exception;
  30. ("#(1) client #(2): unsuccessful receive '#(3)' (code #(4))%N"
  31. # &now # my_pid # exc.description # & exc.error_code).print_on(std_output)
  32. end
  33. else exc := socket.zmq_exception; ("#(1) client #(2): unsuccessful send '#(3)' (code #(4))%N"
  34. # &now # my_pid # exc.description # & exc.error_code).print_on(std_output)
  35. end
  36. end
  37. end
  38. end -- ZMQ_EXAMPLE_CLIENT