Skip to content

Commit

Permalink
add webscoket message_code
Browse files Browse the repository at this point in the history
  • Loading branch information
xmh0511 committed May 31, 2019
1 parent b7e8e7a commit eed5b26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ int main()
websocket_event event;
event.on("message", [](websocket& ws) {
std::cout << ws.messages() << std::endl;
std::cout << (int)ws.message_code() << std::endl;
if (ws.messages() == nonstd::string_view{ "close" }) {
//ws.close();
return;
Expand Down
7 changes: 7 additions & 0 deletions websokcet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ namespace xfinal {
nonstd::string_view messages() const {
return message_;
}
unsigned char message_code() const {
return message_opcode;
}
public:
void write(std::string const& message,unsigned char opcode) {
auto message_size = message.size();
Expand Down Expand Up @@ -204,6 +207,9 @@ namespace xfinal {
unsigned char c = frame[0];
frame_info_.eof = c >> 7;
frame_info_.opcode = c & 15;
if (frame_info_.opcode) {
message_opcode = (unsigned char)frame_info_.opcode;
}
if (frame_info_.opcode == 8) { //关闭连接
close();
return;
Expand Down Expand Up @@ -325,6 +331,7 @@ namespace xfinal {
std::time_t pong_wait_time_ = 60;
std::unique_ptr<asio::steady_timer> wait_timer_;
std::unique_ptr<asio::steady_timer> ping_pong_timer_;
unsigned char message_opcode = 0;
};

template<typename T>
Expand Down

0 comments on commit eed5b26

Please sign in to comment.