Hello team, I am looking for a way to communicate with programs outside Godot and that will be on the same machine, the programs will be developed in C/C++, the goal is to be able to do heavy calculations outside Godot, I tried the modules (it’s great!) but it’s not made to make adjustments often.
I think that network communication is a good idea, there are a lot of different protocols and I don’t know where to start, or I don’t understand!, the CAN bus and the rs232 are ok for me, but there …
Is it possible to have a simple example to send and receive text. I should be able to manage the C/C++ part from the Godot example and post it here,
There is absolutely no need to use any existing protocol. Make one that suits your needs.
I gather from your posting that you have not done any network programming before. If you haven’t, then there are tons of tutorials on the web. Give yourself a couple weeks or more (depending on how much time you can put into it) to get familiar with it in C or C++, and then the Godot end will become almost self-evident.
/* librarian.cpp */
#include "librarian.h"
#include <dlfcn.h>
#include <elf.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <string>
void Librarian::Close() {
dlclose(handle);
}
String Librarian::Get_library_path(String path) {
String retour;
String error;
// Convertion String en char
char Nom_de_la_lib[path.length() + 1];
for (int i = 0; i < path.length(); ++i) { // Copie chaque caractère du string original dans le tableau de char
Nom_de_la_lib[i] = path[i];
}
Nom_de_la_lib[path.length()] = '\0'; // Ajout du caractere final //
// Vérifie si le fichier existe et est accessible
if (access(Nom_de_la_lib, F_OK) == 0) {
handle = dlopen(Nom_de_la_lib, RTLD_LAZY);
if (!handle) // Verifie si le handle est OK
{
error = dlerror();
retour = "Le fichier existe MAIS le handle est pas bon : " + error;
} else {
retour = "Le fichier existe et le handle est OK :";
}
} else {
retour = "Le fichier suivant n'existe pas ou n'est pas accessible: " + path;
}
return retour;
}
int32_t Librarian::Return_Int_NameFunction_Arguments_Int_Int(String Name_Function, int32_t Int_one, int32_t Int_tow) { // Récupérer l'adresse de la fonction add
char NomFonction[Name_Function.length() + 1];
// Cette boucle copie chaque caractère du string original dans le tableau de caractères C++
for (int i = 0; i < Name_Function.length(); ++i) {
NomFonction[i] = Name_Function[i];
}
NomFonction[Name_Function.length()] = '\0'; // Ajout du caractere final
typedef int (*MyFunctionType)(int, int);
MyFunctionType fonction = reinterpret_cast<MyFunctionType>(dlsym(handle, NomFonction));
if (!fonction) {
std::cerr << "Erreur lors de la résolution de la fonction" << std::endl;
dlclose(handle);
return 1;
}
int32_t result = fonction(Int_one, Int_tow);
return result;
}
int32_t Librarian::Return_Int_NameFunction_Arguments_Int(String Name_Function, int32_t Int_one) {
char NomFonction[Name_Function.length() + 1];
// Cette boucle copie chaque caractère du string original dans le tableau de caractères C++
for (int i = 0; i < Name_Function.length(); ++i) {
NomFonction[i] = Name_Function[i];
}
NomFonction[Name_Function.length()] = '\0'; // Ajout du caractere final
typedef int (*MyFunctionType)(int);
MyFunctionType fonction = reinterpret_cast<MyFunctionType>(dlsym(handle, NomFonction));
if (!fonction) {
std::cerr << "Erreur lors de la résolution de la fonction" << std::endl;
dlclose(handle);
return 1;
}
int32_t result = (fonction)(Int_one);
return result;
}
String Librarian::Return_Str_NameFunction_Arguments(String Name_Function) { // Récupérer l'adresse de la fonction add
String Sortie;
char NomFonction[Name_Function.length() + 1];
// Cette boucle copie chaque caractère du string original dans le tableau de caractères C++
for (int i = 0; i < Name_Function.length(); ++i) {
NomFonction[i] = Name_Function[i];
}
NomFonction[Name_Function.length()] = '\0'; // Ajout du caractere final
typedef char *(*MyFunctionType)();
MyFunctionType fonction = reinterpret_cast<MyFunctionType>(dlsym(handle, NomFonction));
String result;
if (!fonction) {
String error = dlerror();
Sortie = "c'est pas OK" + error;
}
char *resultat = fonction();
Sortie = resultat;
return Sortie;
}
String Librarian::Help(String Name_Function) {
char NomFonction[Name_Function.length() + 1];
// Cette boucle copie chaque caractère du string original dans le tableau de caractères C++
for (int i = 0; i < Name_Function.length(); ++i) {
NomFonction[i] = Name_Function[i];
}
NomFonction[Name_Function.length()] = '\0'; // Ajout du caractere final
//return;
}
void Librarian::_bind_methods() {
ClassDB::bind_method(D_METHOD("Get_library_path"), &Librarian::Get_library_path);
ClassDB::bind_method(D_METHOD("Close"), &Librarian::Close);
ClassDB::bind_method(D_METHOD("Help"), &Librarian::Help);
ClassDB::bind_method(D_METHOD("Return_Int_NameFunction_Arguments_Int_Int","int" , "int"), &Librarian::Return_Int_NameFunction_Arguments_Int_Int);
ClassDB::bind_method(D_METHOD("Return_Int_NameFunction_Arguments_Int","int"), &Librarian::Return_Int_NameFunction_Arguments_Int);
ClassDB::bind_method(D_METHOD("Return_Str_NameFunction_Arguments"), &Librarian::Return_Str_NameFunction_Arguments);
}
```Hello, my first working draft for those interested.