I have this code. Its not the entire code because its a Blender addon with many lines that are unrelated to sockets so I give here only the part that deals with the sockets which I kept isolated from the rest of the program.

def create_thread():

    global threadSocket,listening
    threadSocket = threading.Thread(name='threadSocket', target= socket_listen)
    listening = True

def socket_listen():
    global receivedSocket,listening, receivedData,socketServer, socketMessages, pherror

    while listening:
        (receivedSocket , adreess) = socketServer.accept()
        receivedData = (receivedSocket.recv(1024)).decode("utf-8")[:-2]

        receivedSocket.sendall('Hello from Blender!\n')

def create_socket_connection():
    global socketServer
    socketServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

If you want to see the entire code, it can be found here


I am using telnet to test the socket with telnet 4000, telnet can send the data but never receives any. As you can see my socket is blocking inside its own thread so it does not block the entire programs execution. I assume that sendall tries to send everything and for some reason it cannot connect back to telnet for sending . So the only problem here is sending data, if I remove the sendall line the code works fine and even with it , it has no problem receiving data. Am I doing something wrong here ?

I have solved the problem . Stupid mistake, I was using the python 2 docs while my app is python 3. In python 2 sendall sends strings in python 3 it sends binary so a conversion to binary was all it needed.