[Tutor] changing a variable over simple network (with pyOpenGL)
Michael Shulman
contact at endarion.com
Wed Dec 6 12:18:30 CET 2006
Hello,
I am trying to write a very simple py-opengl program pair causing a
variable in each program to be changed by the other. I am able to open
a command window in which I manually assign a value to the variable, but
I cannot seem to implement the udp/ip information I wish to send into a
function which I can call at will. I have tried updating the function
through both a cyclic update function, and the keyboard (keyboard is
preferred, but I tried eliminating it to see if that was the
incompatibility). I do not list any coding for the receiving program,
since it works perfectly with the above code, and is probably correct.
Currently, the program crashes when I press the assigned key. I can't
tell if the issue here is python, or OpenGL, but any help would be very
greatly appreciated!!!
##########Here is what DOES work:
#############################
from socket import *
udpsock = socket(AF_INET, SOCK_DGRAM)
udpsock.bind(('', 0))
udpsock.connect(('localhost', 4550))
try:
while True:
s = raw_input('command> ')
udpsock.send(s)
except EOFError: pass
###########################
#############This is what DOES NOT work:
##############################
from socket import *
udpsock = socket(AF_INET, SOCK_DGRAM)
udpsock.bind(('', 0))
udpsock.connect(('localhost', 4550))
R = 0
def datasender():
global R
try:
while True:
s = input(R)
udpsock.send(s)
except EOFError: pass
def keyboard(key, x, y): #######the keyboard and window OpenGL calls
are not mentioned here, but included properly in the program (they work
with everything except this)
global R
if key == 'k': #####key is arbitrary, I have also tried with
"special keys" as defined by glut
R = R + .01
datasender()
################################
More information about the Tutor
mailing list