Added multicast to Vsend and Vreceive. Updated README. Rediced queue
size to 1 in LiveVideoIn.
diff --git a/Demo/sgi/video/Vreceive.py b/Demo/sgi/video/Vreceive.py
index 8d7150e..415df59 100755
--- a/Demo/sgi/video/Vreceive.py
+++ b/Demo/sgi/video/Vreceive.py
@@ -5,17 +5,22 @@
import sys
import struct
-from socket import *
+from socket import * # syscalls and support functions
+from SOCKET import * # <sys/socket.h>
+from IN import * # <netinet/in.h>
import select
+import struct
import gl, GL, DEVICE
sys.path.append('/ufs/guido/src/video')
import LiveVideoOut
+import regsub
+
+MYGROUP = '225.0.0.250'
+PORT = 5555
PKTMAX = 16*1024
WIDTH = 400
HEIGHT = 300
-HOST = ''
-PORT = 5555
def main():
@@ -23,6 +28,8 @@
if sys.argv[1:]:
port = eval(sys.argv[1])
+ s = opensocket(MYGROUP, port)
+
width, height = WIDTH, HEIGHT
gl.foreground()
@@ -36,9 +43,6 @@
lvo = LiveVideoOut.LiveVideoOut().init(wid, (x, y, width, height), \
width, height)
- s = socket(AF_INET, SOCK_DGRAM)
- s.bind(HOST, port)
-
ifdlist = [gl.qgetfd(), s.fileno()]
ofdlist = []
xfdlist = []
@@ -71,4 +75,35 @@
lvo.close()
+
+# Subroutine to create and properly initialize the receiving socket
+
+def opensocket(group, port):
+
+ # Create the socket
+ s = socket(AF_INET, SOCK_DGRAM)
+
+ # Bind the port to it
+ s.bind('', port)
+
+ # Allow multiple copies of this program on one machine
+ s.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) # (Not strictly needed)
+
+ # Look up the group once
+ group = gethostbyname(group)
+
+ # Ugly: construct binary group address
+ group_bytes = eval(regsub.gsub('\.', ',', group))
+ grpaddr = 0
+ for byte in group_bytes: grpaddr = (grpaddr << 8) | byte
+
+ # Construct struct mreq from grpaddr and ifaddr
+ ifaddr = INADDR_ANY
+ mreq = struct.pack('ll', grpaddr, ifaddr)
+
+ # Add group membership
+ s.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
+
+ return s
+
main()