Unreal Editor freezes/hangs when I execute a Server UDP socket script

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!

You’ve got an infinitely true statement that is polling the connection. I’m guessing you would need to put this in a separate thread for it to not be blocking execution.

1 Like

Thank you. Will definitely try modifying that logic it and see if it runs !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.