Skip to content
This repository was archived by the owner on Aug 21, 2018. It is now read-only.

Commit 03dc835

Browse files
author
matfarre
committed
Added sample python notification listener
1 parent 90ccc29 commit 03dc835

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import socket
2+
import sys
3+
4+
# this listens to notification stream from MSE and displays results in console.
5+
6+
# Create a TCP/IP socket
7+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
9+
# Bind the socket to the address given on the command line
10+
server_address = ('0.0.0.0', 8000) # change this to your ip address
11+
sock.bind(server_address)
12+
# print >>sys.stderr, 'using %s port %s' % sock.getsockname() # use this print statement for python2.7
13+
print (sys.stderr,'using %s port %s' % sock.getsockname()) # use this print statement for python3
14+
sock.listen(1)
15+
16+
while True:
17+
print (sys.stderr, 'waiting for a connection') # use this print statement for python3
18+
# print >>sys.stderr, 'waiting for a connection' # use this print statement for python2.7
19+
connection, client_address = sock.accept()
20+
try:
21+
#print >>sys.stderr, 'client connected:', client_address # use this print statement for python2.7
22+
print (sys.stderr, 'client connected:', client_address) # use this print statement for python3
23+
while True:
24+
data = connection.recv(1024) # change this value, based on your needs.
25+
print (sys.stderr, 'received "%s"' % data) # use this print statement for python3
26+
#print >>sys.stderr, 'received "%s"' % data # use this print statement for python2.7
27+
if data:
28+
connection.sendall(data)
29+
else:
30+
break
31+
finally:
32+
connection.close()

0 commit comments

Comments
 (0)