PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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