Skip to content

Commit 99f5d15

Browse files
Added actual functionality to iOS example
1 parent 0100208 commit 99f5d15

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

example_client_ios/src/ofApp.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "ofxiOS.h"
55
#include "ofxiOSExtras.h"
66

7+
#include "ofxLibwebsockets.h"
8+
79
class ofApp : public ofxiOSApp {
810

911
public:
@@ -23,6 +25,16 @@ class ofApp : public ofxiOSApp {
2325
void gotMemoryWarning();
2426
void deviceOrientationChanged(int newOrientation);
2527

28+
29+
ofxLibwebsockets::Client client;
30+
31+
// websocket methods
32+
void onConnect( ofxLibwebsockets::Event& args );
33+
void onOpen( ofxLibwebsockets::Event& args );
34+
void onClose( ofxLibwebsockets::Event& args );
35+
void onIdle( ofxLibwebsockets::Event& args );
36+
void onMessage( ofxLibwebsockets::Event& args );
37+
void onBroadcast( ofxLibwebsockets::Event& args );
2638
};
2739

2840

example_client_ios/src/ofApp.mm

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,56 @@
11
#include "ofApp.h"
22

3-
//--------------------------------------------------------------
4-
void ofApp::setup(){
3+
string message = "";
54

5+
//--------------------------------------------------------------
6+
void ofApp::setup(){
7+
ofSetLogLevel(OF_LOG_VERBOSE);
8+
client.connect("echo.websocket.org");
9+
// client.connect("echo.websocket.org", true); // optionally use SSL
10+
ofSetLogLevel(OF_LOG_ERROR);
11+
12+
client.addListener(this);
13+
ofSetFrameRate(60);
614
}
715

816
//--------------------------------------------------------------
917
void ofApp::update(){
10-
1118
}
1219

1320
//--------------------------------------------------------------
1421
void ofApp::draw(){
15-
22+
ofDrawBitmapString("Last message: "+message, ofPoint(0,0));
23+
}
24+
25+
//--------------------------------------------------------------
26+
void ofApp::onConnect( ofxLibwebsockets::Event& args ){
27+
cout<<"on connected"<<endl;
28+
}
29+
30+
//--------------------------------------------------------------
31+
void ofApp::onOpen( ofxLibwebsockets::Event& args ){
32+
cout<<"on open"<<endl;
33+
}
34+
35+
//--------------------------------------------------------------
36+
void ofApp::onClose( ofxLibwebsockets::Event& args ){
37+
cout<<"on close"<<endl;
38+
}
39+
40+
//--------------------------------------------------------------
41+
void ofApp::onIdle( ofxLibwebsockets::Event& args ){
42+
cout<<"on idle"<<endl;
43+
}
44+
45+
//--------------------------------------------------------------
46+
void ofApp::onMessage( ofxLibwebsockets::Event& args ){
47+
cout<<"got message "<<args.message<<endl;
48+
message = args.message+" at "+ofGetTimestampString();
49+
}
50+
51+
//--------------------------------------------------------------
52+
void ofApp::onBroadcast( ofxLibwebsockets::Event& args ){
53+
cout<<"got broadcast "<<args.message<<endl;
1654
}
1755

1856
//--------------------------------------------------------------
@@ -22,7 +60,8 @@
2260

2361
//--------------------------------------------------------------
2462
void ofApp::touchDown(ofTouchEventArgs & touch){
25-
63+
client.send("Hello");
64+
cout << "sending hello" <<endl;
2665
}
2766

2867
//--------------------------------------------------------------

0 commit comments

Comments
 (0)