# Blender (BGE) crashes when I open a socket

I am running this script on my BGE... I had issues receiving the socket information inside a while True loop. Then realised that the while was bugging the script.

I also tried to receive the information using a thread, but it didn't work.

So I made the following considering that the script will open the socket every frame of the game but it still crashes my blender.

import bge
import socket
import pickle

UDP_IP = "127.0.0.1"
UDP_PORT = 5005

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

data, addr = sock.recvfrom(1024)
movement = pickle.loads(data)

controller = bge.logic.getCurrentController()
own = controller.owner

own.applyMovement(movement)