Coder Social home page Coder Social logo

ofxsocketio's Introduction

ofxSocketIO

Description

ofxSocketIO is an ofxaddon that wraps socket.io-client-cpp. It is still under active development.

Installation

ofxSocketIO provides the compiled libraries for osx and linux64 out of the box. If you have to compile socket.io-client-cpp yourself, follow the installation instructions.

TLS/SSL

socket.io-client-cpp compiles with SSL support by default. However, we had issues with certificates and thus removed the SSL support. The provided libs (osx and linux64) does not support TLS/SSL.

FYI, we simply removed the find_package(OpenSSL) call in the CMakeLists.txt.

Usage

Take a look at our example.

You'll need a socket.io server to communicate with. (check out our test server)

API

ofxSocketIO

setup(std::string& address)

→ Creates a websocket connection with the address remote.

bindEvent(ofEvent<ofxSocketIOData&>& event, std::string eventName)

→ Binds an ofEvent to string trigger. Typically, you'd do:

std::string eventName = "server-event";
socketIO.bindEvent(serverEvent, eventName);
ofAddListener(serverEvent, this, &ofApp::onServerEvent);

void ofApp::onServerEvent (ofxSocketIOData& data) {
  // Will be triggered when the server emits a "server-event" event
  // See the `ofxSocketIOData` API on how to use the `data` parameter here
}
getStatus()

→ Returns the current status. Either connected, closed, reconnecting or errored.

connectionEvent

→ An ofEvent triggered when the socket is connected to the server

notifyEvent

→ An ofEvent triggered when the socket is connected, closed, errored, or when the socket is trying to reconnect. Comes with std::string status parameter.

emit(std::string& eventName, std::string& data)

→ Emits an event with the specified event name and a string parameter (you'll have to cast your non-string datas).

closeConnection()

→ Force closes the socket.

ofxSocketIOData

getStringValue(std::string key)

→ Get the std::string value for the specified key.

getIntValue(std::string key)

→ Get the int value for the specified key.

getFloatValue(std::string key)

→ Get the float value for the specified key.

getDoubleValue(std::string key)

→ Get the double value for the specified key.

getBoolValue(std::string key)

→ Get the bool value for the specified key.

getVector()

→ Get the raw vector if the message is not a map.

Troubleshooting

ping pong

You may experience issues with 'ping' and 'pong' events, as they are used internally by socket.io:

- `ping`. Fired when a ping packet is written out to the server.
- `pong`. Fired when a pong is received from the server.

source

Credits

ofxSocketIO is maintained by Soixante circuits and hugohil.

It exists thanks to the great work of the socket.io-client-cpp contributors.

These folks have made some useful contributions to ofxSocketIO too:

License

MIT

ofxsocketio's People

Contributors

hugohil avatar mamoroom avatar sy1vain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ofxsocketio's Issues

Event not fired after long period of time

I've set up a Socket.IO server which relay's messages from the client (mobile device) to an OF application. The communication works initially when the server is started, but after a time period (say, 12 hours) the communication fails from the server to the OF side. The client-server communication continues to report console.log statements from the server side but the OF app doesn't receive an event.

A paired down version of the code is available here:
https://gist.github.com/eightlines/a5f57f7a61731a913cb3c0ff33081085

TLS / SSL support

Hi!

I needed to get this to work with a https:// server.
I have compiled the socket.io-client-cpp with TLS (OpenSSH) on MacOSX support and replaced the .h and .a files but I got no success.
I still get:

 [connect] Successful connection
 [error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)

I've checked all the forks and no luck...
On the README.md you say you didn't compile TLS because of certificate issues? Could you elaborate on that, please? Maybe it helps me solve the problem and I can contribute.

Cheers and thanks a lot for all the wonderful work.

Error compile ofxSocketIO

i'm using Ubuntu 16.04 ... but when I tried to compile it cause a lot of problems..
undefined reference to sio::client::socket undefined reference tosio::client::connect, ..

please help me, thank you

Parsing Nested Objects

I'm emitting a SocketIO event from a Node server, and the data I'm sending is a nested JSON. It looks like it the ofxSocketIOData can return strings, bool, ints, etc, but can it parse nested objects, or arrays?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.