summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/msg_client.py
blob: 3c5385777f085e108e305d2aad44b99b06e204cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python2
#client for  msg_daemon

import socket
import sys

# Create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

# Connect the socket to the port where the server is listening
server_address = '/run/msg_socket'
def send_message(message):
    #print >>sys.stderr, 'connecting to %s' % server_address
    try:
        sock.connect(server_address)
    except socket.error, msg:
        print >>sys.stderr, msg
        sys.exit(1)
    try:
        sock.sendall(message)
        #amount_received = 0
        #amount_expected = len(message)

        #while amount_received < amount_expected:
        #    data = sock.recv(16)
        #    amount_received += len(data)
        #    print >>sys.stderr, 'received "%s"' % data

    finally:
        #print >>sys.stderr, 'closing socket'
        print "message sent"
        sock.close()


if __name__ == "__main__":
    if len(sys.argv) == 2:
        send_message(sys.argv[1])
    else:
        print "Unknown command"
        print "usage: %s msg to display" % sys.argv[0]
        sys.exit(2)
    sys.exit(0)