mirror of
https://github.com/socketio/socket.io-client-cpp.git
synced 2026-06-09 19:54:46 +00:00
Bumps [socket.io-parser](https://github.com/socketio/socket.io-parser) to 4.2.3 and updates ancestor dependency [socket.io](https://github.com/socketio/socket.io). These dependencies need to be updated together. Updates `socket.io-parser` from 4.0.5 to 4.2.3 - [Release notes](https://github.com/socketio/socket.io-parser/releases) - [Changelog](https://github.com/socketio/socket.io-parser/blob/main/CHANGELOG.md) - [Commits](https://github.com/socketio/socket.io-parser/compare/4.0.5...4.2.3) Updates `socket.io` from 3.0.5 to 4.6.1 - [Release notes](https://github.com/socketio/socket.io/releases) - [Changelog](https://github.com/socketio/socket.io/blob/main/CHANGELOG.md) - [Commits](https://github.com/socketio/socket.io/compare/3.0.5...4.6.1) --- updated-dependencies: - dependency-name: socket.io-parser dependency-type: indirect - dependency-name: socket.io dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
…
Socket.IO C++ Client
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.
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
- With CMAKE
- Without CMAKE
- With VCPKG
- iOS and OS X
- Option 1: Cocoapods
- Option 2: Create a static library
- Option 3: Manual integration
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
Languages
C++
97.2%
CMake
2.4%
JavaScript
0.4%
