• Stars
    star
    2,243
  • Rank 20,533 (Top 0.5 %)
  • Language
    C++
  • License
    MIT License
  • Created over 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++11 implementation of Socket.IO client

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

Compatibility table

C++ Client version Socket.IO server version
1.x / 2.x 3.x / 4.x
2.x (2.x branch) YES YES, with allowEIO3: true
3.x (master branch) NO YES

Features

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

Note: Only the WebSocket transport is currently implemented (no fallback to HTTP long-polling)

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

More Repositories

1

socket.io

Realtime application framework (Node.JS server)
TypeScript
60,848
star
2

socket.io-client

Realtime application framework (client)
10,608
star
3

socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
Java
5,302
star
4

socket.io-client-swift

Swift
5,199
star
5

engine.io

The engine used in the Socket.IO JavaScript server, which manages the low-level transports such as HTTP long-polling and WebSocket.
4,596
star
6

socket.io-redis-adapter

Adapter to enable broadcasting of events to multiple separate socket.io server nodes.
TypeScript
2,736
star
7

socket.io-p2p

JavaScript
1,027
star
8

engine.io-client

The engine used in the Socket.IO JavaScript client, which manages the low-level transports such as HTTP long-polling, WebSocket and WebTransport.
742
star
9

socket.io-redis-emitter

The Socket.IO Redis emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process.
TypeScript
717
star
10

socket.io-protocol

Socket.IO Protocol specification
JavaScript
504
star
11

engine.io-client-java

Engine.IO Client Library for Java
Java
359
star
12

socket.io-admin-ui

Admin UI for Socket.IO
Vue
344
star
13

socket.io-website

Socket.IO website and blog
JavaScript
318
star
14

engine.io-protocol

Engine.IO protocol
JavaScript
235
star
15

socket.io-adapter

The Socket.IO in-memory adapter
197
star
16

engine.io-server-java

Engine.IO Server Library for Java
Java
168
star
17

socket.io-parser

136
star
18

socket.io-deno

Socket.IO server for Deno
TypeScript
102
star
19

engine.io-parser

Parser for the engine.io protocol, used by client and server
74
star
20

socket.io-msgpack-parser

Socket.IO parser based on msgpack
JavaScript
64
star
21

socket.io-chat-platform

A basic chat platform based on Socket.IO
JavaScript
62
star
22

socket.io-sticky

A simple and performant way to use Socket.IO within a cluster.
JavaScript
42
star
23

socket.io-redis-streams-adapter

The Socket.IO adapter based on Redis Streams, allowing to broadcast events between several Socket.IO servers.
TypeScript
28
star
24

socket.io-postgres-adapter

The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
TypeScript
24
star
25

socket.io-mongo-adapter

The Socket.IO MongoDB adapter, allowing to broadcast events between several Socket.IO servers
TypeScript
24
star
26

socket.io-cluster-adapter

The Socket.IO official cluster adapter, allowing to broadcast events between several Socket.IO servers.
TypeScript
15
star
27

socket.io-json-parser

socket.io parser based on JSON.stringify / JSON.parse
JavaScript
13
star
28

socket.io-benchmarks

Benchmarks for Socket.IO
JavaScript
9
star
29

socket.io-minimal-example

Socket.IO minimal example
HTML
8
star
30

socket.io-compression-demo

JavaScript
7
star
31

get-started-drawing

7
star
32

lz77-compression-demo

JavaScript
7
star
33

socket.io-mongo-emitter

The Socket.IO MongoDB emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process
TypeScript
6
star
34

socket.io-postgres-emitter

The Socket.IO Postgres emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process.
TypeScript
5
star
35

socket.io-echo-server

Socket.IO echo server
JavaScript
4
star
36

socket.io-azure-service-bus-adapter

The Socket.IO adapter for Azure Service Bus, allowing to broadcast events between several Socket.IO servers.
TypeScript
4
star
37

socket.io-aws-sqs-adapter

The Socket.IO adapter for AWS Simple Queue Service (SQS), allowing to broadcast events between several Socket.IO servers.
TypeScript
4
star
38

socket.io-sample-playbook

This repository contains an Ansible playbook to set up a basic Socket.IO application.
JavaScript
4
star
39

tap-to-android

3
star
40

socket.io-swift-fiddle

Swift
2
star
41

socket.io-gcp-pubsub-adapter

The Socket.IO adapter for Google Cloud pub/sub, allowing to broadcast events between several Socket.IO servers
TypeScript
2
star
42

socket.io-browsers

A reusable list of browsers to test when using defunctzombie/zuul
JavaScript
1
star