Skip to content

dustismo/ZeroMQClientServer-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

ZeroMQClientServer-Python

This is a wrapper around the hot-mess that is zeromq async sockets. This provides a threadsafe and latency free way to handle message passing in zeromq. This is a port of the Java version created by @dustismo

Usage:

'''
create a client
you only need a client and a class to handle incoming messages
'''

from com.trendrr.zmq.client.zmq_client_message_handler import ZMQClientMessageHandler

ClientHandler(ZMQClientMessageHandler):

	def incoming(client,message):
		try:
			print message
		except Exception,e:
			print e.message

	def error(x):
		print x.message
 
client = ZMQClient("tcp://localhost:8988", ClientHandler())

#client is threadsafe
client.send("this is a message")

Server

 '''
 this creates a simple echo server
 '''

class ServerHandler(ZMQServerMessageHandler):
			
	def incoming(self, channel,message):
		#just send the message back to the originating user.
		#you could also start a new thread here to handle more intense processing.
		#the channel is threadsafe
		channel.send(message)
			
		
	def error(self, x):
		print x.message


server = new ZMQServer()
server.listen(8988, ServerHandler(), True)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages