#!/usr/bin/python2 #MythVantage osd message deamon. #Use the client to send messages to localhost import socket import sys import os from subprocess import call server_address = '/run/msg_socket' # Make sure the socket does not already exist try: os.unlink(server_address) except OSError: if os.path.exists(server_address): raise # Create a UDS socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) # Bind the socket to the port print >>sys.stderr, 'starting up on %s' % server_address sock.bind(server_address) #change permissions of socket os.chmod(server_address,0777) # Listen for incoming connections sock.listen(1) while True: # Wait for a connection connection, client_address = sock.accept() try: #print >>sys.stderr, 'connection from', client_address msg="" # Receive the data in small chunks and retransmit it while True: data = connection.recv(16) msg+=data if data: continue else: call(["/usr/LH/bin/lh_message.sh", msg]) break finally: # Clean up the connection connection.close()