Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cats a file to a tcp endpoint line by line using streams and zeromq
#!/usr/local/bin
import zmq
import io
import time
import sys
import re
# reads line by line a file and sends it
# to a tcp endpoint using zeromq
# handy to cat big files to a listener
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:8473")
fileName = sys.argv[1]
with io.open(fileName, 'r') as file:
l = file.readline()
while True and l !='':
l1 = l.replace('"','')
l2 = re.sub(r'\\t',' ', l1)
l3 = re.sub(r'\\n', '', l2)
time.sleep(0.01)
#print l3.rstrip('\n')
socket.send_unicode(l3.rstrip('\n'))
l = file.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.