I would like to know how to send a screenshot of the game to a python program through a socket connection.
I already know how to get the image:
var img = getviewport().gettexture().getdata()
The UDP interconnection is ok, but the tcp for to sent the data is not connecting. My first trial was to sent a string, where my python server is:
HOST = '127.0.0.1'
PORT = 4343
sock = socket.socket(socket.AFINET, socket.SOCKSTREAM)
orig = (HOST, PORT)
conn, addr = sock.accept()
print ('Connected to: ', addr)
data = conn.recv(5)
if len(data) == 0:
print("Received: ", data.decode('utf-8'))
My godot client is:
var msg = ">"
thread = Thread.new()
socketTCP = StreamPeerTCP.new()
icon.position.x = get_viewport().size.x/2
icon.position.y = get_viewport().size.y/2
vel_x = rand_range(5,20)
vel_y = rand_range(5,20)
print("v_x: " + str(vel_x))
print("v_y: " + str(vel_y))
move_obj.wait_time = interval
print("thread already active")
print("starting thread ...")
print("Thread ID: " + str(thread.get_id()))
print("thread is working!!!")
print("thread not working!!!")
var done = false
ip = "127.0.0.1"
port = 4343
connection = socketTCP.connect_to_host("127.0.0.1",4343)
done = socketTCP.is_connected_to_host()
socketTCP.put_utf8_string("Test of connection")
Any idea of how to sent the img through this connection?