-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsender.py
More file actions
43 lines (30 loc) · 939 Bytes
/
sender.py
File metadata and controls
43 lines (30 loc) · 939 Bytes
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
43
#
# mostly copied from
# http://bioportal.weizmann.ac.il/course/python/PyMOTW/PyMOTW/docs/socket/multicast.html
#
import socket
import struct
import sys
import time
import json
multicast_group = ('224.3.29.71', 10000)
values = {'hostname': 'my new nickname is Rambo',
'resolution':['1920x480'],
'capabibility': ['png']}
message = json.dumps( values, sort_keys=True, indent=4, separators=(',', ': '))
# Create the datagram socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Set a timeout so the socket does not block indefinitely when trying
# to receive data.
sock.settimeout(0.2)
counter = 0
try:
while True:
counter +=1
# Send data to the multicast group
print >>sys.stderr, '%d: sending "%s"' % (counter, message )
sent = sock.sendto(message, multicast_group)
time.sleep( 5 )
finally:
print >>sys.stderr, 'closing socket'
sock.close()