Dears,
My Unreal Engine 5 Editor freezes/hangs when I execute a Server UDP socket script (Python). I am able to run fairly simple scripts, but this particular script freezes or hangs the editor and I have to shut it down from task manager.
I have been try to debug this since last week. I couldn’t, hence posting it on forum. It might be some of you have faced a similar problem and could have figured it out!
My aim is to have ‘client.py’ and ‘server.py’ ‘talk’/send and receive data to each other via UE5.
Here are the PY files.
Server.py:-
import socket
if __name__ == "__main__":
host = "127.0.0.1"
port = 4455
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind((host, port))
while True:
data, addr = server.recvfrom(1024)
data = data.decode("utf-8")
if data == "!EXIT":
print("Client disconnected.")
print(f"Client: {data}")
data = data.upper()
data = data.encode("utf-8")
server.sendto(data, addr)
server.close()
and client.py:-
import socket
if __name__ == "__main__":
host = "127.0.0.1"
port = 4455
addr = (host, port)
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
data = input("Enter a word: ")
if data == "!EXIT":
data = data.encode("utf-8")
client.sendto(data,addr)
print("Disconnected from the server.")
break
data = data.encode("utf-8")
client.sendto(data, addr)
data, addr = client.recvfrom(1024)
data = data.decode("utf-8")
print(f"Server: {data}")
client.close
Thank you!