I use an external library to deal with udp (OSC) communication between 2 apps. To format the messages that will be sent, the library is expecting a char* but I get a string from the UI that I have to convert.
While I was dealing with other parts of my code the udp part was hard coded like that :
char* endofMess = "from setEndMess";
and was working fine. I thought it would be easy to get it working with my strings and wrote :
std::string s = "from setEndMess";
char* endofMess = const_cast<char*>(s.c_str());
but unlike for the first example where I was receiving the message correctly formatted, I now receive only gibberish characters. Does somebody know where it can come from?
Thanks!
Matthieu
EDIT : the code I use : The method to send the message each time OSCVal will change :
void osc500::testOSC(int identifier, float OSCval)
{
UdpTransmitSocket transmitSocket( IpEndpointName( destIP, port ) );
char buffer[1024];
osc::OutboundPacketStream p( buffer, 1024 );
p << osc::BeginBundleImmediate
<< osc::BeginMessage( endofMess )
<< OSCval << osc::EndMessage
<< osc::EndBundle;
transmitSocket.Send( p.Data(), p.Size() );
}
And if I have to change the OSC pattern I call this one :
void osc500::setEndMess(String endpattern){
// endofMess = "from setEndMess"; //OK works fine each time it's called
//1st try :
//std::string s = "from setEndMess";
//endofMess = const_cast<char*>(s.c_str()); //gibberish
//2nd try :
//std::string s = "from setEndMess";
//endofMess = &s[0]; //gibberish
//3rd & 4th tries :
//char s[4] = {'t','e','s','t'};
//char s[5] = {'t','e','s','t','\0'};
//endofMess = s; //gibberish
}
char*
or if you're passing that to a network function for it to be sent on the wire. – Janiculum