Init, run until socket is connected
(controller)
| 41 | import itertools |
| 42 | |
| 43 | def init(controller): |
| 44 | """ |
| 45 | Init, run until socket is connected |
| 46 | """ |
| 47 | |
| 48 | # run once per frame |
| 49 | if controller.sensors[0].positive and controller.sensors[1].positive: |
| 50 | |
| 51 | ### SOCKET DEFINITION |
| 52 | # run once |
| 53 | # if not hasattr(logic, 'socket'): |
| 54 | |
| 55 | # define socket, set socket parameters |
| 56 | logic.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 57 | |
| 58 | logic.socket.setblocking(0) |
| 59 | timeOut = 0.001 |
| 60 | logic.socket.settimeout(timeOut) |
| 61 | |
| 62 | # bind socket (run until binded) |
| 63 | host = '127.0.0.1' |
| 64 | port_rcv = 10000 |
| 65 | logic.socket.bind((host,port_rcv)) |
| 66 | print('bind socket: IP = {} Port = {}'.format(host, port_rcv)) |
| 67 | |
| 68 | controller.owner['SocketConnected'] = True |
| 69 | |
| 70 | ### IMAGE TEXTURE |
| 71 | # get screen object |
| 72 | obj = logic.getCurrentScene().objects['VideoScreen'] |
| 73 | # get the reference pointer (ID) of the texture |
| 74 | ID = texture.materialID(obj, 'MAVideoMat') |
| 75 | # create a texture object |
| 76 | logic.texture = texture.Texture(obj, ID) |
| 77 | |
| 78 | # logic.imageIndex = 0 |
| 79 | |
| 80 | def run(controller): |
| 81 | """ |