Blender freezes on socket script execution

So I have a simple Python script to receive data from a client with socket. The script works fine outside of Blender and functions in Blender as well (I can see incoming data from the client when I run Blender from the terminal). However Blender’s GUI freezes on script execution and no further input is possible in the GUI.

The script is as follows:

#!/usr/bin/env python3


#SERVER


import bge
import socket


def Main():
    host = '127.0.0.1'
    port = 5000


    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((host,port))




    print ( "Server Started.")
    while True:
        data, addr = s.recvfrom(1024)
        print ( "message From: " + str(addr))
        print ( "from connected user: " + data.decode())
    c.close()


if __name__ == '__main__':
    Main()

I’m brand new to Python and Blender so any help would be greatly appreciated.

To clarify, the result is the same when I take out the while loop. Like this:

#!/usr/bin/env python3


#SERVER


import bge
import socket


def Main():
    host = '127.0.0.1'
    port = 5000


    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.bind((host,port))




    print ( "Server Started.")
    data, addr = s.recvfrom(1024)
    print ( "message From: " + str(addr))
    print ( "from connected user: " + data.decode())


if __name__ == '__main__':
    Main()

And I’m using an Always Sensor with True level triggering connected to a Python controller to run my script.

I think I’m using the right terminology…