Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Somehow SOLVED! OscSender/OscReceiver not sending or receiving

$
0
0

@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:0

How 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

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles