Skip to content

Instantly share code, notes, and snippets.

@fishkingsin
Created April 29, 2013 04:50
Show Gist options
  • Select an option

  • Save fishkingsin/5479765 to your computer and use it in GitHub Desktop.

Select an option

Save fishkingsin/5479765 to your computer and use it in GitHub Desktop.
ios bonjour client
#pragma once
#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"
#include "ofxBonjour.h"
using namespace ofxBonjour;
class testApp : public ofxiPhoneApp{
public:
void setup();
void update();
void draw();
void exit();
void touchDown(ofTouchEventArgs & touch);
void touchMoved(ofTouchEventArgs & touch);
void touchUp(ofTouchEventArgs & touch);
void touchDoubleTap(ofTouchEventArgs & touch);
void touchCancelled(ofTouchEventArgs & touch);
void lostFocus();
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);
void discoveredServices( vector<NSNetService*> & services );
void gotServiceData( Service & service );
Client bonjourClient;
};
//--------------------------------------------------------------
void testApp::setup(){
// initialize the accelerometer
ofxAccelerometer.setup();
//If you want a landscape oreintation
//iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);
ofBackground(127,127,127);
ofAddListener(ofxBonjour::Events().onServicesDiscovered, this, &testApp::discoveredServices);
ofAddListener(ofxBonjour::Events().onServiceDiscovered, this, &testApp::gotServiceData );
bonjourClient.discover("_ecs._tcp.");
}
//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
}
//--------------------------------------------------------------
void testApp::discoveredServices( vector<NSNetService*> & services ){
for (int i=0; i<services.size(); i++){
cout<< [services[i].description cStringUsingEncoding:NSUTF8StringEncoding] << endl;
}
}
//--------------------------------------------------------------
void testApp::gotServiceData( Service & service ){
cout<< service.ipAddress << ":" << service.port << endl;
}
//--------------------------------------------------------------
void testApp::exit(){
}
//--------------------------------------------------------------
void testApp::touchDown(ofTouchEventArgs & touch){
}
//--------------------------------------------------------------
void testApp::touchMoved(ofTouchEventArgs & touch){
}
//--------------------------------------------------------------
void testApp::touchUp(ofTouchEventArgs & touch){
}
//--------------------------------------------------------------
void testApp::touchDoubleTap(ofTouchEventArgs & touch){
}
//--------------------------------------------------------------
void testApp::touchCancelled(ofTouchEventArgs & touch){
}
//--------------------------------------------------------------
void testApp::lostFocus(){
}
//--------------------------------------------------------------
void testApp::gotFocus(){
}
//--------------------------------------------------------------
void testApp::gotMemoryWarning(){
}
//--------------------------------------------------------------
void testApp::deviceOrientationChanged(int newOrientation){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment