How To Convert a Message Sent From Godot To Another Application?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AydinHumphries


With help in a separate topic, I was able to send a message from Godot to another application Pd. The topic linked:

However, the only character that is sent is a semicolon and it is not received by Pd as a semicolon but by the character, .

I want to be able to send any string. Additionally I want to know what ports it is safe to use but I suppose that is better saved for a different topic.

Anyway, the Godot file has one scene, “SendMessage.tscn” with a Node2D root node that is parent to a Control node that is parent to two buttons - “buttonConnect” (connection “_on_connect” to Control node) and “buttonbuttonMessage” (connection “_on_message” to Control node). The Control node also has one script, “”:

extends Control
var socket

func _ready():
	socket =

func _on_connect():
	socket.connect_to_host("", 4242)

func _on_message():

This is the entire project, however it can also be cloned from github:

Any help with converting my strings so more than just ; can be received would be greatly appreciated, thanks.

:bust_in_silhouette: Reply From: klaas

i’ve answered in your other question. But it suits better here …

Godot sends the string length first when using put_string, this could be the problem.
try this …

 put_data("my message;".to_ascii())

sure, I didn’t know if you were going to have time to respond or not so I started a new thread, sorry about that.


put_data("my message;".to_ascii())

so I have tried putting this in line 13 and 14 of my code, also tried putting it under the “ready” function. but wherever I put it, it returns an error

The method “put_data” isn’t declared in the current class.

I’m not sure how to declare it properly, sorry - do you have any idea?

AydinHumphries | 2020-09-11 22:08

you have to call it on socket

socket.put_data("my message;".to_ascii())

klaas | 2020-09-11 22:14

oh wow, I have received the message on Pd properly now:

tcp:my message

thanks for that

I also have respelled it as myMessage, as pd doesn’t receive messages with spaces well except in some instances where the spaces separate a list of floats or symbols (strings) to be interpreted for different purposes. I don’t know much about FUDI but in Pd the semicolons are usually only used to separate a list from the next. but as the information is coming in externally in this instance maybe the semicolon is needed (I don’t really know actually).

anyway, it might not be important but it seems there is just one small bug: I have tried both spellings of “my message;” and “myMessage;” - the issue is that in both cases it prints twice in Pd. for my message, it is:

tcp: message
tcp: my message

and then for myMessage,

tcp: myMessage

I mean it is probably insignificant - the main thing is that I’m receiving messages. I was just wondering if you have any idea what that maybe? perhaps godot sends out two messages, one for line 14:


and again for line 15:


that’s my best guess.

AydinHumphries | 2020-09-11 22:26

never mind, I managed to get just one message by deleting the line above - I believe it is not necessary and can be replaced by the line of code you gave me.

thanks again for your support - it helped me a great deal!

AydinHumphries | 2020-09-11 22:43

:bust_in_silhouette: Reply From: medicaldarman

this question is very good