-
Notifications
You must be signed in to change notification settings - Fork 20
Häfner edited this page Jul 13, 2015
·
2 revisions
To send or receive messages via UDP use the socket python library.
Add the following script to PolyVR and trigger it with a timeout each 50 ms.
import socket, VR
if not hasattr(VR, 'udpsock'):
VR.udpsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # internet, UDP
VR.udpsock.bind( ('localhost', 6060) )
VR.udpsock.setblocking(0)
try:
data, addr = VR.udpsock.recvfrom(10)
print "received message:", float(data)
except:
pass
Add another script to your PolyVR project to configure your socket on demand:
import socket, VR
VR.udpsock.close()
VR.udpsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # internet, UDP
VR.udpsock.setblocking(0)
VR.udpsock.bind( ('localhost', 6060) )
Test it with the following python script:
import socket
msg = "Hello, World!"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msg, ('141.3.150.20', 6060))