File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 39395 . Add ` <your boost install folder>/lib ` to library search path, add ` boost.lib ` (Win32) or ` -lboost ` (Other) link option.
40406 . Include ` sio_client.h ` in your client code where you want to use it.
4141
42+ ## Quick start
43+ The APIs are similar with JS client.
44+
45+ Connect to a server
46+ ``` C++
47+ sio::client h;
48+ h.connect(" http://127.0.0.1:3000" );
49+ ```
50+
51+ Emit a event
52+ ``` C++
53+ // emit text
54+ h.socket()->emit ("add user", username);
55+ //emit binary
56+ char buf[ 100] ;
57+ h.socket()->emit("add user", std::make_shared< std::string > (&buf,100));
58+ //emit message object with lambda ack handler
59+ h.socket()->emit("add user", string_message::create(username), [ &] (message::ptr const& msg)
60+ {
61+ });
62+ ```
63+
64+ Bind a event
65+ ```C++
66+ /**************** bind with function pointer ***************/
67+ void OnMessage(sio::event &)
68+ {
69+
70+ }
71+
72+ h.socket()->on("new message", &OnMessage);
73+ /********************* bind with lambda ********************/
74+ h.socket()->on("login", [&](sio::event& ev)
75+ {
76+ //handle login message
77+ //post to UI thread if any UI updating.
78+ });
79+
80+ /**************** bind with member function *****************/
81+ class MessageHandler
82+ {
83+ public:
84+ void OnMessage(sio::event &);
85+ };
86+ MessageHandler mh;
87+ h.socket()->on("new message",std::bind( &MessageHandler::OnMessage,&mh,std::placeholders::_1));
88+ ```
89+ Send to other namespace
90+ ``` C++
91+ h.socket(" /chat" )->emit ("add user", username);
92+ ```
93+
4294## API
4395### *Overview*
4496There're just 3 roles in this library - `socket`,`client` and `message`.
You can’t perform that action at this time.
0 commit comments