Hi Guys,
I managed to learn openframeworks and c++ quit fast thanks to great examples you guys provide.
It’s more fun to learn by examples than reading dozens of articles/books.
But somethings wasn’t clear to my.
People use TCP to be sure the packets arrive at their the destination.
TCP has builtin error checking and retransmitting.
The TCP sender sample sends the same message every update loop.
Wouldn’t be better to add typed at line 44 in testApp.ccp and add a typed=false at the end
if(weConnected){
if(typed)
{
tcpClient.send(msgTx);
cout << "send" << endl;
//if data has been sent lets update our text
string str = tcpClient.receive();
if( str.length() > 0 ){
msgRx = str;
}
typed = false;
}
I don’t see the point of sending the same message every update loop ?
The udp sample does the oposite then the TCP sample
It sends data once the mouse is released, while UDP is made to send a lot of data really fast.
I would change the upd sender.
void testApp::mouseDragged(int x, int y, int button){
stroke.push_back(ofPoint(x,y));
string message="";
//for(int i=0; i<stroke.size(); i++){
message=ofToString(x)+"|"+ofToString(y)+"[/p]";
//}
int sent = udpConnection.Send(message.c_str(),message.length());
}
void testApp::mouseReleased(int x, int y, int button){
//string message="";
//for(int i=0; i<stroke.size(); i++){
// message+=ofToString(stroke[i].x)+"|"+ofToString(stroke[i].y)+"[/p]";
//}
//int sent = udpConnection.Send(message.c_str(),message.length());
}
Then remove the stroke.clear() at the udp receiver
void testApp::update(){
char udpMessage[100000];
udpConnection.Receive(udpMessage,100000);
string message=udpMessage;
if(message!=""){
//stroke.clear();
float x,y;
vector<string> strPoints = ofSplitString(message,"[/p]");
for(int i=0;i<strPoints.size();i++){
vector<string> point = ofSplitString(strPoints[i],"|");
x=atof(point[0].c_str());
y=atof(point[1].c_str());
point.clear();
stroke.push_back(ofPoint(x,y));
}
}
}
I could be wrong but I think these little changes make better use of the protocols
zip file with VS projects
http://www.lab101.be/networkSamples.zip