Skip to content

More examples for Igor to Igor communication #68

Description

@t-b

@timjarsky FYI

Code taken from tests/RunTests.pxp.

For use within one Igor instance a call to DoXOPIdle is required before fetching the message via zeromq_client_recv().

For Igor to Igor communication it is easier to use zeromq_set(ZeroMQ_SET_FLAGS_DEBUG) so that the polling is done internally as the defaults include "busy wait on receive".

Function SendMessage()

	zeromq_client_connect("tcp://127.0.0.1:5555")

	string msg = "{                "+\
	    "\"version\" : 1,          "+\
	     "\"CallFunction\" : {     "+\
	       "\"name\" : \"CallMe\"  "+\
	     "}                        "+\
	  "}"
	  
    zeromq_client_send(msg)
	print zeromq_client_recv()
End

Function ClientLoop()

	zeromq_stop()
	zeromq_set(ZeroMQ_SET_FLAGS_DEBUG)
	zeromq_client_connect("tcp://127.0.0.1:5555")

	string/G msg = "{                "+\
	    "\"version\" : 1,            "+\
	     "\"CallFunction\" : {       "+\
	       "\"name\" : \"TestFunctionNoArgs\"   "+\
	     "}                          "+\
	  "}"


	for(;;)
		zeromq_client_send(msg)
		string reply = zeromq_client_recv()

		if(numtype(strlen(reply)) != 0 || strlen(reply) == 0)
			break
		endif
		
		printf "Received reply: %s\r", reply
	endfor
End

Function ServerLoop()

	string reply, identity

	zeromq_stop()
	zeromq_set(ZeroMQ_SET_FLAGS_DEBUG)
	zeromq_server_bind("tcp://127.0.0.1:5555")
	
	for(;;)
		string msg = zeromq_server_recv(identity)
		
		if(numtype(strlen(msg)) != 0 || strlen(msg) == 0)
			break
		endif

		printf "msg: %s\r", msg
		printf "identity: %s\r", identity		

		reply = zeromq_test_callfunction(msg)
		printf "Sending reply: %s\r", reply
		zeromq_server_send(identity, reply)
	endfor
End

Function SendMessageToServer()

	zeromq_stop()
	zeromq_client_connect("tcp://127.0.0.1:" + num2str(5555))

	string/G msg = "{                "+\
	    "\"version\" : 1,            "+\
	     "\"CallFunction\" : {       "+\
	       "\"name\" : \"GetWave\"   "+\
	     "}                          "+\
	  "}"

	for(;;)
		zeromq_client_send(msg)
		string reply = zeromq_client_recv()

//		if(numtype(strlen(reply)) != 0 || strlen(reply) == 0)
//			break
//		endif

		printf "Received reply: %s\r", reply
		
		break
	endfor
End

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions