@mvs wrote:
Hi dear Forum,
i have been trying to send one integer data to another app and seem to not be very succesfull at it.
I would appreciate it if you would have a look and give me a hint on my mistake. (In header, setup and update i am writing only the Osc relevant lines)
The draw function in sender prints the distance values all right YET
The draw function in receiver only prints
buf = "listening for osc messages on port 12345
distance:0How can i control the sent message in sender?
SENDER
//--------------------------------------------------------------
ofApp.h
int distance;
ofxOscSender sender;
//--------------------------------------------------------------
void ofApp::setup()
sender.setup("localhost", 12345);
//--------------------------------------------------------------
void ofApp::update()if (kinect.isFrameNew()) { // here there are some kinect related stuff) // if (contourFinder.blobs.size() > 0) { for (int i = contourFinder.blobs[0].centroid.x - 8; i < contourFinder.blobs[0].centroid.x + 8; i++) { for (int j = contourFinder.blobs[0].centroid.y - 8; j < contourFinder.blobs[0].centroid.y + 8; j++) { distance += kinect.getDistanceAt(i, j); } } distance /= 64; } //in or out of if clause???? ofxOscMessage m; m.setAddress("/object"); m.addIntArg(distance); sender.sendMessage(m, false); }
//--------------------------------------------------------------
void ofApp::draw() {std::cout << "distance: " << distance << endl; //writes the distance in mm on command window //this writes the distance value on the console allright
}
RECEIVER
//--------------------------------------------------------------
ofApp.h
(hashtag) define PORT 12345
int distance;
ofxOscReceiver receiver;//--------------------------------------------------------------
void ofApp::setup()
cout << "listening for osc messages on port " << PORT << "\n";
receiver.setup(PORT);
distance = 0;
//--------------------------------------------------------------
void ofApp::update()while (receiver.hasWaitingMessages()) { ofxOscMessage m; receiver.getNextMessage(m); if (m.getAddress() == "/object") { distance = m.getArgAsInt(0); } }
//--------------------------------------------------------------
void ofApp::draw()string buf; buf = "listening for osc messages on port" + ofToString(PORT); ofDrawBitmapString(buf, 10, 20); buf = "distance: " + ofToString(distance, 4); ofDrawBitmapString(buf, 430, 20);
Posts: 3
Participants: 1