GithubHelp home page GithubHelp logo

presleyhank / socket.io-client-cpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from socketio/socket.io-client-cpp

0.0 3.0 0.0 671 KB

C++11 implementation of Socket.IO client

License: MIT License

CMake 1.31% C++ 98.26% JavaScript 0.44%

socket.io-client-cpp's Introduction

Socket.IO C++ Client

Build Status

By virtue of being written in C++, this client works in several different platforms. The examples folder contains an iPhone, QT and Console example chat client! It depends on websocket++ and is inspired by socket.io-clientpp.

Clients with iPhone, QT, Console and web

Features

  • 100% written in modern C++11
  • Compatible with socket.io 1.0+ protocol
  • Binary support
  • Automatic JSON encoding
  • Multiplex support
  • Similar API to the Socket.IO JS client
  • Cross platform

Installation alternatives

Quickstart

** Full overview of API can be seen here **

The APIs are similar to the JS client.

Connect to a server

sio::client h;
h.connect("http://127.0.0.1:3000");

Emit an event

// emit event name only:
h.socket()->emit("login");

// emit text
h.socket()->emit("add user", username);

// emit binary
char buf[100];
h.socket()->emit("add user", std::make_shared<std::string>(buf,100));

// emit message object with lambda ack handler
h.socket()->emit("add user", string_message::create(username), [&](message::list const& msg) {
});

// emit multiple arguments
message::list li("sports");
li.push(string_message::create("economics"));
socket->emit("categories", li);

Items in message::list will be expanded in server side event callback function as function arguments.

Bind an event

Bind with function pointer
void OnMessage(sio::event &)
{

}
h.socket()->on("new message", &OnMessage);
Bind with lambda
h.socket()->on("login", [&](sio::event& ev)
{
    //handle login message
    //post to UI thread if any UI updating.
});
Bind with member function
class MessageHandler
{
public:
    void OnMessage(sio::event &);
};
MessageHandler mh;
h.socket()->on("new message",std::bind( &MessageHandler::OnMessage,&mh,std::placeholders::_1));

Using namespace

h.socket("/chat")->emit("add user", username);

** Full overview of API can be seen here **

License

MIT

socket.io-client-cpp's People

Contributors

melode11 avatar jianjunz avatar hfossli avatar lniccoli avatar nuclearace avatar francoisvdv avatar evileye2000 avatar joelnordell avatar laneysmith avatar mehanig avatar yas avatar llamerada-jp avatar yandod avatar limitedatonement avatar nuclearcookie avatar

Watchers

James Cloos avatar DAVID TIM avatar  avatar

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.