Problem with script in Game Engine

I have problem with python script in game engine. That script running OK (I see it in console), but Game engine freeze.

Does anybody knows where the problem is?
thaks for any help


import socket
import string

HOST = ‘localhost’
PORT = 8778
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

cont = GameLogic.getCurrentController()
own = cont.getOwner()

bone = GameLogic.getCurrentScene().getObjectList()[“cube”]

while 1:
data = s.recv(4096)
b = string.find(data, “X=”)
c = string.find(data, “_”)
P = data[b+2:c]
X = float§
print X
d = string.find(data, “Y=”)
e = string.find(data, “_Z”)
Q= data[d+2:e]
Y = float(Q)
print Y
f = string.find(data, “Z=”)
g = string.find(data, “_end”)
R= data[f+2:g]
Z = float®
print Z


I have Blender 2.44

When do you think this loop would stop looping?
while 1:

I need continual data flow. Do you think that I have to use another type of cycle?

If you trigger the script through the regular gamelogic python controller and have the sensor set to allways, the script will rerun automaticly for every frame… so no need to loop.
Now your script just loops internally on the first frame… so the game has no chance to progress.

Scripts in BGE have to finish as soon as possible, because BGE waits for them. And you have infinite cycle inside the script, so it never finish and so BGE cannot continue.

Another problem is that recv() blocks processing of script until it receives some data. So it can also cause lagging, even if server sends data constantly. You can use socket’s method setblocking() to change this behaviour.