no message
This commit is contained in:
parent
7417a488ed
commit
f458f77e0b
@ -6,30 +6,30 @@
|
||||
<Label name="title" text="新建监听项" valign="center" margin="60,15,0,0" align="left" width="stretch" height="35" font="arial_14"/>
|
||||
</HBox>
|
||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
||||
<Label name="title" text="类型:" valign="bottom" margin="30,0,0,0" width="60" height="30" font="arial_14"/>
|
||||
<Combo class="list" name="combo_type" height="30" width="110" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
||||
<Label name="title" text="类型:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
||||
<Combo class="list" name="combo_type" height="30" width="130" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
||||
<Control width="stretch"/>
|
||||
</HBox>
|
||||
<VBox bkcolor="bk_wnd_darkcolor" height="100" visible="false" name="uart_config">
|
||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
||||
<Label name="title" text="串口:" valign="bottom" margin="30,0,0,0" width="60" height="30" font="arial_14"/>
|
||||
<Label name="title" text="串口:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
||||
<Combo class="list" name="uart_type" height="30" width="110" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
||||
<Control width="stretch"/>
|
||||
</HBox>
|
||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
||||
<Label name="title" text="波特率:" valign="bottom" margin="30,0,0,0" width="60" height="30" font="arial_14"/>
|
||||
<Label name="title" text="波特率:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
||||
<Combo class="list" name="uart_baurate_select" height="30" width="110" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
||||
<Control width="stretch"/>
|
||||
</HBox>
|
||||
</VBox>
|
||||
<VBox bkcolor="bk_wnd_darkcolor" height="90" visible="false" name="ip_config">
|
||||
<HBox width="stretch" height="35" margin="10,0,0,0">
|
||||
<Label name="title" text="ip: " valign="bottom" margin="30,0,0,0" width="60" height="30" font="arial_14"/>
|
||||
<Label name="title" text="ip: " valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
||||
<RichEdit class="simple input" width="90" name="ip_edit" height="30" margin="0,3" padding="6,6,6" />
|
||||
<Control width="stretch"/>
|
||||
</HBox>
|
||||
<HBox width="stretch" height="35" margin="10,0,0,0">
|
||||
<Label name="title" text="端口:" valign="bottom" margin="30,0,0,0" width="60" height="30" font="arial_14"/>
|
||||
<Label name="title" text="端口:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
||||
<RichEdit class="simple input" width="90" name="port_input" height="30" margin="0,3" padding="6,6,6" />
|
||||
<Control width="stretch"/>
|
||||
</HBox>
|
||||
|
@ -466,6 +466,19 @@ void BasicForm::InitWindow(){
|
||||
node->SetClass(L"list_topitem");
|
||||
node->SetFixedHeight(30);
|
||||
mMonitor->GetRootNode()->AddChildNode(node);
|
||||
|
||||
|
||||
node = new ui::TreeNode;
|
||||
node->SetText(nbase::StringPrintf(L"websocket client"));
|
||||
node->SetClass(L"list_topitem");
|
||||
node->SetFixedHeight(30);
|
||||
mMonitor->GetRootNode()->AddChildNode(node);
|
||||
|
||||
node = new ui::TreeNode;
|
||||
node->SetText(nbase::StringPrintf(L"websocket server"));
|
||||
node->SetClass(L"list_topitem");
|
||||
node->SetFixedHeight(30);
|
||||
mMonitor->GetRootNode()->AddChildNode(node);
|
||||
}
|
||||
|
||||
mRightSide = dynamic_cast<ui::TabBox*>(FindControl(L"tab_side"));
|
||||
|
@ -264,6 +264,22 @@ void NewMonitorForm::InitWindow()
|
||||
element->SetTextPadding({ 6,0,6,0 });
|
||||
element->SetText(nbase::StringPrintf(L"udp group"));
|
||||
m_combo_type->Add(element);
|
||||
|
||||
element = new ui::ListContainerElement;
|
||||
element->SetClass(L"listitem");
|
||||
element->SetFixedHeight(30);
|
||||
element->SetBkColor(L"white");
|
||||
element->SetTextPadding({ 6,0,6,0 });
|
||||
element->SetText(nbase::StringPrintf(L"websocket server"));
|
||||
m_combo_type->Add(element);
|
||||
|
||||
element = new ui::ListContainerElement;
|
||||
element->SetClass(L"listitem");
|
||||
element->SetFixedHeight(30);
|
||||
element->SetBkColor(L"white");
|
||||
element->SetTextPadding({ 6,0,6,0 });
|
||||
element->SetText(nbase::StringPrintf(L"websocket client"));
|
||||
m_combo_type->Add(element);
|
||||
}
|
||||
m_ip_config_vbox = dynamic_cast<ui::VBox*>(FindControl(L"ip_config"));
|
||||
m_uart_config_vbox = dynamic_cast<ui::VBox*>(FindControl(L"uart_config"));
|
||||
|
@ -81,7 +81,7 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include;$(ProjectDir);$(ProjectDir)third\include\lua</IncludePath>
|
||||
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include;$(ProjectDir);$(ProjectDir)third\include\lua;$(ProjectDir)third\include\boost171;$(ProjectDir)third\include\</IncludePath>
|
||||
<ReferencePath>$(ReferencePath)</ReferencePath>
|
||||
<LibraryPath>$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)third\lib</LibraryPath>
|
||||
</PropertyGroup>
|
||||
@ -179,6 +179,7 @@
|
||||
<ClCompile Include="udp_libevent.cpp" />
|
||||
<ClCompile Include="utils.cpp" />
|
||||
<ClCompile Include="lua_bind.cpp" />
|
||||
<ClCompile Include="websocket_client.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="base_form.h" />
|
||||
@ -198,6 +199,7 @@
|
||||
<ClInclude Include="udp_group_form.h" />
|
||||
<ClInclude Include="udp_libevent.h" />
|
||||
<ClInclude Include="utils.h" />
|
||||
<ClInclude Include="websocket_client.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="..\Debug\resources\themes\default\basic\basic.xml" />
|
||||
|
@ -16,11 +16,13 @@ void defaultConnRead(char* p, uint32_t len) {
|
||||
|
||||
class ServerCallbacks {
|
||||
public:
|
||||
static void cb_listener(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr* addr, int len, void* ptr);
|
||||
static void cb_listener(struct evconnlistener* listener,
|
||||
evutil_socket_t fd, struct sockaddr* addr, int len, void* ptr);
|
||||
static void server_run(TcpServerLibevent* p);
|
||||
};
|
||||
|
||||
ConnectionLibevent::ConnectionLibevent(TcpServerLibevent* p, struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1) :
|
||||
ConnectionLibevent::ConnectionLibevent(TcpServerLibevent* p,
|
||||
struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1) :
|
||||
m_parent_server(nullptr),
|
||||
m_event(nullptr),
|
||||
m_fd(-1),
|
||||
@ -33,7 +35,8 @@ ConnectionLibevent::ConnectionLibevent(TcpServerLibevent* p, struct bufferevent*
|
||||
m_addr = p1;
|
||||
}
|
||||
|
||||
ConnectionLibevent::ConnectionLibevent(struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1) :
|
||||
ConnectionLibevent::ConnectionLibevent(struct bufferevent* ev,
|
||||
uint32_t fd, struct sockaddr_in* p1) :
|
||||
m_parent_server(nullptr),
|
||||
m_event(nullptr),
|
||||
m_fd(-1),
|
||||
|
98
examples/proto_debuger/websocket_client.cpp
Normal file
98
examples/proto_debuger/websocket_client.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
#include "websocket_client.h"
|
||||
#include "websocketpp/config/asio_no_tls_client.hpp"
|
||||
#include "websocketpp/client.hpp"
|
||||
#include <iostream>
|
||||
|
||||
typedef websocketpp::client<websocketpp::config::asio_client> client;
|
||||
|
||||
using websocketpp::lib::placeholders::_1;
|
||||
using websocketpp::lib::placeholders::_2;
|
||||
using websocketpp::lib::bind;
|
||||
|
||||
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
|
||||
|
||||
void on_open(client* c, websocketpp::connection_hdl hdl)
|
||||
{
|
||||
std::string msg = "hello";
|
||||
c->send(hdl, msg, websocketpp::frame::opcode::text);
|
||||
c->get_alog().write(websocketpp::log::alevel::app, "Tx: " + msg);
|
||||
}
|
||||
|
||||
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg)
|
||||
{
|
||||
std::cout << "on_message called with hdl: " << hdl.lock().get()
|
||||
<< " and message: " << msg->get_payload()
|
||||
<< std::endl;
|
||||
websocketpp::lib::error_code ec;
|
||||
//c->send(hdl,msg->get_payload(),msg->get_opcode(),ec);
|
||||
if (ec)
|
||||
{
|
||||
std::cout << "Echo failed because " << ec.message() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//定时器回调函数
|
||||
void Timeout(client* c, websocketpp::connection_hdl& hdl, boost::asio::deadline_timer* pt, const boost::system::error_code& ec)
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
std::cout << "timer is cancel " << std::endl;
|
||||
return;
|
||||
}
|
||||
static int count = 0;
|
||||
c->send(hdl, "hello", websocketpp::frame::opcode::text);
|
||||
count++;
|
||||
if (count > 5)//定时器触发五次后关闭连接
|
||||
{
|
||||
c->close(hdl, websocketpp::close::status::normal, "");
|
||||
return;
|
||||
}
|
||||
pt->expires_at(pt->expires_at() + boost::posix_time::seconds(5));
|
||||
pt->async_wait(bind(Timeout, c, hdl, pt, ::_1));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int TestPoint(int argc, char* argv[])
|
||||
{
|
||||
client c;
|
||||
|
||||
std::string uri = "ws://xx.xx.xx.xx:xxx";
|
||||
|
||||
c.set_access_channels(websocketpp::log::alevel::all);
|
||||
c.clear_access_channels(websocketpp::log::alevel::frame_payload);
|
||||
c.clear_access_channels(websocketpp::log::alevel::frame_header);
|
||||
|
||||
// 初始化 ASIO
|
||||
c.init_asio();
|
||||
|
||||
// 注册消息回调
|
||||
|
||||
c.set_message_handler(bind(&on_message, &c, ::_1, ::_2));
|
||||
c.set_open_handler(bind(&on_open, &c, _1));
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
client::connection_ptr con = c.get_connection(uri, ec);
|
||||
con->add_subprotocol("janus-protocol");
|
||||
if (ec)
|
||||
{
|
||||
std::cout << "could not create connection because: " << ec.message() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto hdl = con->get_handle();
|
||||
c.connect(con);
|
||||
|
||||
boost::asio::deadline_timer t(c.get_io_service(), boost::posix_time::seconds(5)); //设置一个5s超时的定时器
|
||||
t.async_wait(bind(&Timeout, &c, hdl, &t, ::_1));
|
||||
|
||||
std::thread th([&c] { c.run(); });
|
||||
|
||||
//休眠13s后取消定时器并关闭连接
|
||||
sleep(13);
|
||||
t.cancel();
|
||||
c.close(hdl, websocketpp::close::status::normal, "");
|
||||
|
||||
th.join();
|
||||
}
|
7
examples/proto_debuger/websocket_client.h
Normal file
7
examples/proto_debuger/websocket_client.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
class WebsocketClient
|
||||
{
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user