TCP Socket Listener, Receiving Binary Data into UE4 From a Python Script!

Thank you for the code. I used your code and could get tcp connection in Unreal but still could not receive the data yet. I wrote the tcp sender script in python.



import socket

s = None

def openConnection(TCP_PORT=8888):
    TCP_IP = '127.0.0.1'
    BUFFER_SIZE = 1024
    global s

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TCP_IP, TCP_PORT))

def sendMessage(MESSAGE):
    s.send(MESSAGE)

def closeConnection():
    s.close()


I tested by let my unreal project in play mode.
and in python


sender.openConnection(8888)

And I see “Connection accepted from …”

but when running


sender.sendMessage("ASdfsdf")

No log about received data. It looks like when tcp was connected, HandleConnectionAccepted was called and no data at that time yet. When receiving message, no callback is called.

Since I am new to tcp so not sure if I test it right.

I would appreciate if you could show your script for testing.

Thanks,