|
1 | 1 | #include "ofApp.h" |
2 | 2 |
|
3 | | -//-------------------------------------------------------------- |
4 | | -void ofApp::setup(){ |
| 3 | +string message = ""; |
5 | 4 |
|
| 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); |
6 | 14 | } |
7 | 15 |
|
8 | 16 | //-------------------------------------------------------------- |
9 | 17 | void ofApp::update(){ |
10 | | - |
11 | 18 | } |
12 | 19 |
|
13 | 20 | //-------------------------------------------------------------- |
14 | 21 | 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; |
16 | 54 | } |
17 | 55 |
|
18 | 56 | //-------------------------------------------------------------- |
|
22 | 60 |
|
23 | 61 | //-------------------------------------------------------------- |
24 | 62 | void ofApp::touchDown(ofTouchEventArgs & touch){ |
25 | | - |
| 63 | + client.send("Hello"); |
| 64 | + cout << "sending hello" <<endl; |
26 | 65 | } |
27 | 66 |
|
28 | 67 | //-------------------------------------------------------------- |
|
0 commit comments