no message

This commit is contained in:
zcy 2022-03-13 18:50:41 +08:00
parent 1572832de6
commit d547b64721
6 changed files with 154 additions and 7 deletions

View File

@ -281,7 +281,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
TcpServerInfo* info = (TcpServerInfo*)wParam;
ui::TreeNode* node = new ui::TreeNode;
mMonitor->GetRootNode()->GetChildNode(5)->AddChildNode(node);
mMonitor->GetRootNode()->GetChildNode(6)->AddChildNode(node);
auto key = info->ip;
node->SetText(key);
node->SetClass(L"listitem");

View File

@ -212,7 +212,14 @@ void NewMonitorForm::InitWindow()
if (m_combo_type->GetText() == L"websocket client") {
wprintf(L"%s\r\n", m_ip_select->GetText().c_str());
wprintf(L"%s\r\n", m_port_select->GetText().c_str());
WebsocketClient* wsclient = new WebsocketClient(wstring2string(m_ip_select->GetText().c_str()),true);
WebsocketClient* wsclient = nullptr;
if (m_ip_select->GetText().find(L"wss") == 0) {
wsclient = new WebsocketClient(wstring2string(m_ip_select->GetText().c_str()), true);
}
else {
wsclient = new WebsocketClient(wstring2string(m_ip_select->GetText().c_str()), false);
}
TcpServerInfo* p = new TcpServerInfo;
p->ip = m_ip_select->GetText();
@ -232,7 +239,8 @@ void NewMonitorForm::InitWindow()
wprintf(L"%s\r\n", m_port_select->GetText().c_str());
int port = atoi(wstring2string(m_port_select->GetText()).c_str());
WebsocketServer* wsserver = new
WebsocketServer(wstring2string(m_ip_select->GetText().c_str()), atoi(wstring2string(m_port_select->GetText()).c_str()));
WebsocketServer(wstring2string(m_ip_select->GetText().c_str()),
atoi(wstring2string(m_port_select->GetText()).c_str()));
TcpServerInfo* p = new TcpServerInfo;
p->ip = m_ip_select->GetText();
@ -383,17 +391,15 @@ void NewMonitorForm::InitWindow()
this->m_uart_baurate_select->Add(element);
}
}
if ((text == L"tcp client")|| (text == L"tcp server") ||
if ((text == L"tcp client")|| (text == L"tcp server") || (text == L"websocket server") ||
(text == L"udp") || (text == L"udp group")) {
this->m_ip_config_vbox->SetVisible(true);
this->m_uart_config_vbox->SetVisible(false);
m_port_select->SetVisible(true);
m_ip_select->SetText(L"127.0.0.1");
m_port_select->SetText(L"9001");
}
if ( (text == L"websocket server") || (text == L"websocket client")) {
if ((text == L"websocket client")) {
this->m_ip_config_vbox->SetVisible(true);
this->m_uart_config_vbox->SetVisible(false);
m_port_select->SetVisible(false);

View File

@ -0,0 +1 @@
require("string") local file = io.open("writetest.txt", "w+") function OnWebSocketData(data) if nil == file then print("open file writetest.txt fail") end file:write("OnUartData from lua " .. data) file:flush() showdata("dfasdfsddfasda" .. data.."\r\n") end

View File

@ -30,6 +30,7 @@ void on_message(WebsocketServer* s, websocketpp::connection_hdl hdl, message_ptr
// check for a special command to instruct the server to stop listening so
// it can be cleanly exited.
/*
if (msg->get_payload() == "stop-listening") {
s->m_server->stop_listening();
return;
@ -41,6 +42,7 @@ void on_message(WebsocketServer* s, websocketpp::connection_hdl hdl, message_ptr
std::cout << "Echo failed because: "
<< "(" << e.what() << ")" << std::endl;
}
*/
}
WebsocketServer::WebsocketServer(std::string server,uint32_t port){

View File

@ -0,0 +1,82 @@
#include "websocket_server_form.h"
#include "utils.h"
#define WEBSOCKET_SERVER_LUA "websocket_server.lua"
WebsocketServerForm::WebsocketServerForm(ui::Window* hwnd, string url, WebsocketServer* server)
{
if (nullptr != hwnd) {
this->SetWindow(hwnd, nullptr, false);
}
m_server = server;
if (nullptr != server) {
}
mLua = new LuaDelegate;
mLuaFile.open(WEBSOCKET_SERVER_LUA);
std::string lua_script;
if (mLuaFile.is_open()) {
std::string s;
while (getline(mLuaFile, s)) {
lua_script += s + "\r\n";
}
mLuaFile.close();
}
mLuaScript = lua_script;
mLua->DoString(lua_script);
this->mLua->BindFunction("showdata", LuaShowData);
}
void WebsocketServerForm::Init()
{
ui::ChildBox::Init();
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"server_info"));
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_recv_edit"));
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script_edit"));
m_rich_edit_2->SetRich(true);
m_rich_edit_2->SetReturnMsgWantCtrl(true);
m_rich_edit_2->SetText(string2wstring(mLuaScript));
m_websocket_send_edit = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_send_edit"));
m_btn_send_data = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
m_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
m_btn_save_lua = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
m_btn_close_form = dynamic_cast<ui::Button*>(FindSubControl(L"btn_close_uart"));
if (nullptr != m_btn_save_lua)
m_btn_save_lua->AttachClick(
[this](ui::EventArgs* ev) {
std::cout << "±£´ælua½Å±¾\r\n";
std::string lua = wstring2string(this->m_rich_edit_2->GetText());
if (0 == this->mLua->UpdateScript(lua)) {
this->mLuaScript = lua;
mLuaFileEdit = std::ofstream(WEBSOCKET_SERVER_LUA,
std::ios::out | std::ios::trunc);
mLuaFileEdit.write(lua.c_str(), lua.size());
mLuaFileEdit.flush();
mLuaFileEdit.close();
}
else {
MessageBox(0, L"lua½Å±¾´íÎó", L"", 0);
return true;
}
std::cout << lua.c_str() << "\r\n";
return true;
}
);
}
LuaDelegate* WebsocketServerForm::LuaVM()
{
return mLua;
}
void WebsocketServerForm::ShowDataInEdit(const char*src)
{
m_rich_edit_1->AppendText(string2wstring(std::string(src)), false);
}

View File

@ -0,0 +1,56 @@
#pragma once
#pragma once
#include <string>
#include "msgdef.h"
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include "base/base.h"
#include "serial_port.h"
#include "duilib/UIlib.h"
#include "tcp_client.h"
#include "lua_wraper.h"
#include "global.h"
#include <fstream>
#include "udp_libevent.h"
#include <istream>
#include "websocket_client.h"
#include "lua_bind.h"
#include "websocket_server.h"
class WebsocketServerForm :
public ui::ChildBox,
LuaBindInterface
{
public:
WebsocketServerForm(ui::Window* hwnd,
string url, WebsocketServer* server);
virtual void Init() override;
LuaDelegate* LuaVM();
void ShowDataInEdit(const char*) ;
private:
ui::Label* m_label_1;
ui::RichEdit* m_rich_edit_1;
ui::RichEdit* m_rich_edit_2;
ui::RichEdit* m_websocket_send_edit;
ui::Button* m_btn_send_data;
ui::Button* m_btn_save_lua;
ui::Button* m_btn_close_form;
ui::CheckBox* m_check_box_1;
ui::CheckBox* m_check_box_2;
ui::CheckBox* m_check_box_3;
ui::CheckBox* m_check_box_4;
std::string m_url;
WebsocketServer* m_server;
std::fstream mLuaFileRead;
std::ofstream mLuaFileEdit;
LuaDelegate* mLua;
std::string mLuaScript;
std::ifstream mLuaFile;
};