File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ # xwebsocket
2
+ c++11 websocket parser builder. small ,simple and fast
3
+ ```
4
+ int main()
5
+ {
6
+ std::map<int64_t, xwebsocket::session> sessions_;
7
+ int64_t session_id_ = 0;
8
+ int64_t msg_count_ = 0;
9
+ xwebsocket::xserver server(1);
10
+ server.bind("127.0.0.1", 9001).
11
+ regist_accept_callback([&](xwebsocket::session &&sess) {
12
+
13
+ sess.regist_frame_callback([session_id_, &sessions_, &msg_count_]
14
+ (std::string &&payload, xwebsocket::frame_type type, bool){
15
+
16
+ if (type == xwebsocket::frame_type::e_connection_close)
17
+ return sessions_[session_id_].close();
18
+ ++msg_count_;
19
+ std::cout << payload << std::endl;
20
+ sessions_[session_id_].send_text("hello world: " + std::to_string(msg_count_));
21
+ });
22
+ sess.regist_close_callback([session_id_, &sessions_] {
23
+ sessions_.erase(session_id_);
24
+ });
25
+ sessions_.emplace(session_id_, std::move(sess));
26
+ session_id_++;
27
+ });
28
+
29
+ server.start();
30
+ return 0;
31
+ }
32
+ ```
You can’t perform that action at this time.
0 commit comments