Added client mode support to HTTP::Websocket, added websockettest binary, added ws/wss protocol support to HTTP::URL, added support for websockets and socket overriding to HTTP::Downloader, fixed HTTP parser not handling response codes 1XX, 204 and 304 correctly.
This commit is contained in:
parent
57b930020b
commit
37af199a1c
9 changed files with 214 additions and 42 deletions
51
test/websocket.cpp
Normal file
51
test/websocket.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <mist/config.h>
|
||||
#include <mist/timing.h>
|
||||
#include <mist/websocket.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
Util::Config c(argv[0]);
|
||||
|
||||
JSON::Value option;
|
||||
option["arg_num"] = 1;
|
||||
option["arg"] = "string";
|
||||
option["help"] = "URL to retrieve";
|
||||
c.addOption("url", option);
|
||||
if (!(c.parseArgs(argc, argv))){return 1;}
|
||||
|
||||
Util::redirectLogsIfNeeded();
|
||||
Socket::Connection C;
|
||||
HTTP::Websocket ws(C, HTTP::URL(c.getString("url")));
|
||||
if (!ws){return 1;}
|
||||
while (ws){
|
||||
if (!ws.readFrame()){
|
||||
Util::sleep(100);
|
||||
continue;
|
||||
}
|
||||
switch (ws.frameType){
|
||||
case 1:
|
||||
std::cout << "Text frame (" << ws.data.size() << "b):" << std::endl
|
||||
<< std::string(ws.data, ws.data.size()) << std::endl;
|
||||
break;
|
||||
case 2:{
|
||||
std::cout << "Binary frame (" << ws.data.size() << "b):" << std::endl;
|
||||
size_t counter = 0;
|
||||
for (size_t i = 0; i < ws.data.size(); ++i){
|
||||
std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)(ws.data[i] & 0xff) << " ";
|
||||
if ((counter) % 32 == 31){std::cout << std::endl;}
|
||||
counter++;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}break;
|
||||
case 8:
|
||||
std::cout << "Connection close frame" << std::endl;
|
||||
C.close();
|
||||
break;
|
||||
case 9: std::cout << "Ping frame" << std::endl; break;
|
||||
case 10: std::cout << "Pong frame" << std::endl; break;
|
||||
default: std::cout << "Unknown frame (" << (int)ws.frameType << ")" << std::endl; break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue