websocket-cpp

所属分类:Websocket编程
开发工具:C++
文件大小:0KB
下载次数:0
上传日期:2015-10-25 11:22:30
上 传 者sh-1993
说明:  C++WebSockets服务器
(C++ WebSockets Server)

文件列表:
CMakeLists.txt (1082, 2015-10-25)
Server.hpp (870, 2015-10-25)
details/ (0, 2015-10-25)
details/Acceptor.hpp (1508, 2015-10-25)
details/Connection.hpp (5404, 2015-10-25)
details/ServerLogic.hpp (3112, 2015-10-25)
details/base64.hpp (867, 2015-10-25)
details/frames.hpp (4488, 2015-10-25)
details/handshake.hpp (2630, 2015-10-25)
details/http.hpp (3787, 2015-10-25)
details/http_parser.hpp (5426, 2015-10-25)
details/sha1.hpp (4382, 2015-10-25)
docs/ (0, 2015-10-25)
docs/rfc2616.txt (422279, 2015-10-25)
docs/rfc6455.txt (162067, 2015-10-25)
server_fwd.hpp (280, 2015-10-25)
server_src.hpp (3835, 2015-10-25)
tests/ (0, 2015-10-25)
tests/base64_tests.cpp (890, 2015-10-25)
tests/frames_tests.cpp (3032, 2015-10-25)
tests/handshake_tests.cpp (2503, 2015-10-25)
tests/http_parser_tests.cpp (1423, 2015-10-25)
tests/main.cpp (254, 2015-10-25)
tests/regression_tests.cpp (6009, 2015-10-25)
tests/sha1_tests.cpp (1616, 2015-10-25)
third_party/ (0, 2015-10-25)
third_party/catch/ (0, 2015-10-25)
third_party/catch/LICENSE_1_0.txt (1338, 2015-10-25)
third_party/catch/catch.hpp (336879, 2015-10-25)
websocket-cpp.cpp (94, 2015-10-25)

# WebSockets for C++ *Version 0.1 alpha* Quick and dirty implementation of WebSocket server. For testing purposes only. ## Example websocket::Server server; // listen on 0.0.0.0:8888 // log errors to stderr server.start("0.0.0.0", 8888, std::cerr); ... // check for a new event websocket::Event event; websocket::ConnectionId connId; std::string message; if (server.poll(event, connId, message) { switch (event) { case websocket::Event::NewConnection: std::cout << '#' << connId << " connected\n"; break; case websocket::Event::Message: std::cout << '#' << connId << " says " << message << '\n'; // send reply server.send(connId, message); break; case websocket::Event::Disconnect: std::cout << '#' << connId << " disconnected\n"; break; } } ... // stop server server.stop(); // destructor also can call stop(), but it's better to do it explicitly ## Features and limitations * Fragmented messages are not supported * Client can't send a message longer than 125 bytes * Server can't send a message longer than UINT32_MAX bytes * Server doesn't validate client text frames. ## Overview of the WebSocket protocol ### Handshake Client sends HTTP GET request GET /some/path/with/optional?query HTTP/1.1 Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Version: 13 ... other fields ... Server replies with HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= and then they send *data frames* for each other ### Client data frames Data frames from client looks like this: XX YY [LL LL | LL LL LL LL LL LL LL LL] KK KK KK KK [data] where * `XX` - byte with opcode and the "final fragment" flag, 0x81 for non-fragmented text frame. * `YY` - byte with data length, high bit is set to 1, i.e. 0x85 for 5-byte data. If length is 126, next two bytes are real 16-bit length. If length is 127, next eight bytes are real 64-bit length. * `KK` - four bytes of the *masking key* * `data` - data bytes XORed with the masking key, `data[i] ^ key[i % 4]`. Example: 81 85 F0 F0 F0 F0 C1 C2 C3 C4 C5 -- text "12345" ### Server data frames Almost like client frames, but without masking. XX LL [LL LL | LL LL LL LL LL LL LL LL] [data] * `XX` - opcode and "final fragment" flag. * `LL` - data length (0 - 125), 126 and 127 for extended length. * `data` - data bytes. Example: 81 05 31 32 33 34 35 -- text "12345" ## License **websocket-cpp** is placed in the public domain. ## External links * [RFC 6455](http://tools.ietf.org/html/rfc6455) - The WebSocket Protocol

近期下载者

相关文件


收藏者